jQuery对话框没有关闭

时间:2013-07-27 21:08:11

标签: jquery jquery-ui

我的警报已到达且有效,但close方法无效。知道为什么吗?

我的javascript:

  var myDialog = $('#divContactUs');

  myDialog.dialog({
               autoOpen: false,
               title: "Send Us A Note:",
               modal: true,
               buttons: [{
                   id: "btn-send",
                   text: "Send",
                   click: function () {
                       // you can now use the reference to the dialog
                       myDialog.dialog("close");
                       alert('test');
                   }
               }]

           });
       });

我的HTML:

<div id="divContactUs" style="display:none">
Name: &nbsp <input type="text" name="Name" /><br />
Email: &nbsp <input type="text" name="Email" /><br />
Phone: &nbsp <input type="text" name="Phone" /><br />
Message:<br />
<textarea name="Message"></textarea>
</div>

3 个答案:

答案 0 :(得分:2)

在按钮的范围内,单击$(this)指的是按钮,而不是模态。我会先将模态选择器设置为变量,然后再引用它;

var myDialog = $('#divContactUs');

myDialog.dialog({
    autoOpen: false,
    title: "Send Us A Note:",
    modal: true,
    buttons: [{
        id:"btn-send",
        text: "Send",
        click: function() {
            // you can now use the reference to the dialog
            myDialog.dialog("close")
        }
    }
});

答案 1 :(得分:0)

你的脚本正在运行。不要忘记添加分号;添加行$(this).dialog("close");的结尾。

这是一个证明它的jsFiddle JsFiddle

答案 2 :(得分:0)

有时IE会抛出错误&#34;未指定的错误&#34;。

try{ 
    $(selector).dialog("close");.
}catch(e){
    $(selector).parent().hide();
}
相关问题