我对 jQuery 非常陌生,并且一直在尝试理解以下 js 以用于 aspx 表单。它一直在创建一个'对象函数没有方法'parseJSON''错误。有人告诉我,使用自定义函数并创建一个 jQuery 选择器来代替使用会更可取。我已经了解到选择器应该看起来像 $("#powerform") 但是在单击提交按钮时无法让我的 iframe/webform 调用它。我很难理解什么:
function $(elem) {return document.getElementById(elem);} //simple id reference
这会导致我的网页错误,因此尝试创建选择器。完整的 js 如下所示:
function $(elem) {return document.getElementById(elem);} //simple id reference
number_messages = 0;
var last_id = "";
function check_messages() { //check for messages from iframe
if (location.hash != last_id) {
last_id = location.hash;
number_messages++;
last_id = last_id.replace("_"," ");
last_id = last_id.substr(1);
last_id = last_id.substr(0,last_id.indexOf("&"));
var message_color;
var extra_text;
if(last_id=="Signing Complete" || last_id=="Viewing Complete"){
message_color="green";
extra_text = "";
}else{
message_color="red";
extra_text = "<p style='text-align:center'><button type='button' onclick='window.location=\"embedded.html\"' style='display:inline;'>Reload form?</button> </p>";
}
document.getElementById("powerform").innerHTML = "<center><h3 style='color:"+message_color+";border:none;font-size:20px;text-align:center;'>" + last_id + "</h3><br/>"+extra_text+"</center>";
}
}
function open_embeddedform(form) {
var form_url = "https://demo.docusign.net/MEMBER/PowerFormSigning.aspx?PowerFormId=5044d9a2-341d-4490-9f9a-cd5f29fdcc62";
form_url += "&Therapist_UserName=" + $("Therapist_UserName").value;
form_url += "&Therapist_Email=" + $("Therapist_Email").value;
//for (var i=0; i < form.Windows.length; i++) {
// if (form.Windows[i].checked) {
// form_url += "&Windows=" + form.Windows[i].value;
//}
//}
//alert(form_url);
$("powerform").innerHTML = '<iframe id="document" src="' + form_url + '" border="0"></iframe>';
}
setInterval(check_messages, 200);
随之而来的html是:
<div id="powerform" runat="server">
<script type="text/javascript" src="jscripts/open_powerform.js"></script>
<form name="embedded_powerform" action="open_form(this.form);">
<label for="Therapist_UserName">Full Name</label>
<input type="text" name="Therapist_UserName" id="Therapist_UserName">
<div class="clear"></div>
<label for="Therapist_Email">Email</label>
<input type="text" name="Therapist_Email" id="Therapist_Email">
<div class="clear"></div>
<br><center>
<button type="button" onclick="open_embeddedform(this.form);">Submit</button></center>
</form>
</div>
很抱歉这样一个菜鸟问题和长篇文章。如果可能的话,我感谢任何人的反馈。谢谢