jQuery UI 模式对话框不阻塞
我是 javascript 和 jQuery 的新手。我正在尝试使用 jQuery UI 小部件实现模式对话框。
模态对话框正确显示了“确定”和“取消”按钮,但对话框(“打开”)函数调用似乎不会阻止并等待“确定”或“取消”单击。例如,当我运行以下代码时
.....在按钮单击时
okToDelete = false; //a global variable
$('deleteDialog').dialog('open'); //this does not block but returns immediately
alert(okToDelete == true ? "ok" : "false");
首先显示警报框,然后然后显示模式对话框! okToDelete 是一个全局变量,我在进入函数时设置为 false,并在“确定”按钮回调中设置为 true。
这是我的对话框初始化函数
$("#deleteDialog").dialog({
bgiframe: true,
autoOpen: false,
modal: true,
overlay: {
backgroundColor: '#000',
opacity: 0.5
},
buttons: {
Cancel: function() {
$(this).dialog('close');
},
Ok: function() {
$(this).dialog('close');
okToDelete = true;
}
}
});
I am new to javascript and jQuery. I am trying to implement a modal dialog using jQuery UI widgets.
The modal dialog shows up correctly with OK and Cancel buttons, but the dialog('open') function call does not seem to block and wait for an OK or Cancel click. For example, when I run the following code
.....on button click
okToDelete = false; //a global variable
$('deleteDialog').dialog('open'); //this does not block but returns immediately
alert(okToDelete == true ? "ok" : "false");
The alert box is displayed first and THEN the modal dialog shows up! okToDelete is a global variable I set to false when I enter the function and set to true in the OK button callback.
Here is my dialog init function
$("#deleteDialog").dialog({
bgiframe: true,
autoOpen: false,
modal: true,
overlay: {
backgroundColor: '#000',
opacity: 0.5
},
buttons: {
Cancel: function() {
$(this).dialog('close');
},
Ok: function() {
$(this).dialog('close');
okToDelete = true;
}
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它并不是要“阻止”。如果您想在对话框关闭后显示警报(我假设这是为了测试)或调用其他函数,如果您将其放置在
callback
或ok
中,<代码>取消功能。看看这个:
http://docs.jquery.com/UI/Dialog#event-close
文档中的事件
close
:该事件在对话框关闭时触发。
代码示例
提供回调函数来处理关闭事件作为 init 选项。
通过类型绑定到关闭事件:dialogclose。
It is not meant to 'block'. If you want to display the alert (I assume that's for testing) or call other functions after the dialog closes, if you to place it within the
callback
or theok
,cancel
functions.Check this out:
http://docs.jquery.com/UI/Dialog#event-close
The event
close
from the docs:This event is triggered when the dialog is closed.
Code examples
Supply a callback function to handle the close event as an init option.
Bind to the close event by type: dialogclose.