jQuery对话框未关闭
我的警报已达到并起作用,但close方法不起作用。知道为什么吗 我的javascript:jQuery对话框未关闭,jquery,jquery-ui,Jquery,Jquery Ui,我的警报已达到并起作用,但close方法不起作用。知道为什么吗 我的javascript: var myDialog = $('#divContactUs'); myDialog.dialog({ autoOpen: false, title: "Send Us A Note:", modal: true, buttons: [{
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:   <input type="text" name="Name" /><br />
Email:   <input type="text" name="Email" /><br />
Phone:   <input type="text" name="Phone" /><br />
Message:<br />
<textarea name="Message"></textarea>
</div>
名称:
电子邮件:
电话:
消息:
在按钮范围内,单击$(此)
指的是按钮,而不是模式。我会先将模式选择器设置为一个变量,然后再引用它
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")
}
}
});
您的脚本正在运行。不要忘记添加分号
代码>添加行的结尾$(this).dialog(“close”)代码>
这里有一个jsFiddle来证明它有时候IE会抛出一个错误“未指定的错误”
嗯,我原以为这样就行了,但我还是有同样的问题。还有其他想法吗?我在过去一个小时左右修改了很多次……我在上面添加了我最新的代码。如果我在close方法之前添加了警报,那么警报会工作,但在它的当前位置,我没有到达警报。您使用的是什么模式库?我刚刚更改了jQuery和jQuery UI的版本,现在工作正常。谢谢Jivings:)你学到了一些东西,但我会保留分号“只是为了安全”。
try{
$(selector).dialog("close");.
}catch(e){
$(selector).parent().hide();
}