“Jquery”对话框错误


Jquery dialog box error

我正在使用一个对话框在我的页面上显示和提交查询表单。当我尝试一次又一次地调用它时,我遇到了问题。第一次一切正常,表单提交成功。但是如果我点击 GO 按钮(在下面添加了 html)。我收到此行文档的错误。编辑:

<div class="hidden" id="dialog">
    <form action="index.php" class="testForm" id="testForm">
        <div class="name" id="name">
            <div class="displayName" id="dispName">Name</div>
            <div class="textName" id="viewName"><input type="text" class="fname" id="fullName" /></div>
            <div class="hide" id="nameErr"></div>
        </div>
        <div class="address" id="addressDetails">
            <div class="displayAddress" id="dispAddress">Address</div>
            <div class="textAddress" id=""><input type="text" class="taddress" id="fullAddress" /></div>
            <div class="hide" id="addressErr"></div>
        </div>
        <div class="submitForm" ><input type="button" class="submitDetails" id="submitInfo" name="Submit" value="Submit" onClick="validateAndSubmitForm()"/>
        <a name="Close" onclick="$('#dialog').dialog('close');">Close</a>
        </div>
    </form>
    </div>

Javascript''jquery

function submitEnquiryForProperty()

{

document.forms.testForm.reset();
$("#dialog").dialog({
                modal:true,
                resizable:false,
                autoOpen:false,
                width:260,
        });
openDialog();   

}

  function openDialog(){
$("#dialog").dialog("open");    
  }
  function closeDialog(){
$("#dialog").dialog("close");   
 }

表单提交时的回调函数

$.ajax({
            type:'POST',
            url:"processForm.php",
            data:"name="+name+"&address="+address,
            dataType:"html",
            success:function(msg){
                if(msg=="success"){
                    $("#dialog", window.parent.document).html("<div class='pad5'><div class='flt' style='padding-left:3px; width:235px;'><div class='thanx_msg'>Thank you for submitting the details. <br /><div class='spacer5'>&nbsp;</div><span class='gre'>Our Sales team shall revert to your query soon.</span></div></div><div class='spacer5'>&nbsp;</div><div style='padding-left:3px;' class='text'><strong>You can also:</strong></div><div style='margin-left:20px; line-height:20px;'>&bull; Apply for a <a href='homeloan.php'>Home Loan</a><br />&bull; Visit <a href='http://www.proptiger.com'>proptiger.com</a> for more properties<br />&bull; See our <a href='http://www.proptiger.com/blog'>Blog</a> for latest updates</div></div><br/><div class='msg' style='color:red;'>Click to close the box</div>");
                    $(function(){
                                $('#dialog').click(function() {
                                    closeDialog();
                                });
                            });
                }
                else
                {
                    alert("Operation cannot be completed,please try again");        
                }
            }

但我面临着同样的问题。.reset()行出错。
谢谢你的时间。

更新了答案

如果要有一个可重用的对话框,请按如下方式操作:

  1. 在初始HTML中包含对话框元素(几乎可以肯定是<div>)。使用 CSS 类,使其不会立即可见,例如:

    HTML:
    <div id="dialog" class="hidden">...</div>
    CSS:
    .hidden { display: none }
    
  2. 在页面加载后立即无条件地从 Javascript 调用$("#dialog").dialog(options)。请务必在选项中设置autoOpen: false

  3. 每当要显示对话框时,请使用 $("#dialog").dialog("open")

  4. 每当要隐藏对话框时,请使用 $("#dialog").dialog("close")

  5. 根据需要重复步骤 3 和 4。

.dialog( "destroy" )

完全删除对话框功能。这会将元素返回到其初始化前的状态。

.dialog( "close" )

关闭对话框。