使用jqueryUI 对话框模仿confirm()
我想使用 jQueryUI 对话框来模拟标准 JavaScript 确认()。我正在考虑类似以下的事情,但我显然不明白它应该如何工作。有什么建议吗?谢谢
return $("#dialog-cancel").dialog("open");
$("#dialog-cancel").dialog({
autoOpen: false,height: 400,width: 350,modal: true,
open: function(event, ui){},
buttons: {'OK': function(){$(this).dialog("close");return true;},'CANCEL': function() {$(this).dialog("close");return false;}}
});
I would like to mimic a standard JavaScript confirm() using a jQueryUI dialog. I was thinking of something like the following, but I am obviously not understanding how it should work. Any suggestions? Thank you
return $("#dialog-cancel").dialog("open");
$("#dialog-cancel").dialog({
autoOpen: false,height: 400,width: 350,modal: true,
open: function(event, ui){},
buttons: {'OK': function(){$(this).dialog("close");return true;},'CANCEL': function() {$(this).dialog("close");return false;}}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
副本确实没什么用。我对此感到抱歉。
基于这个答案,我会做:
创建一个函数,该函数将创建一个基本模式对话框消息和确定/取消按钮
接受单击时执行的两个按钮的两个回调
好处是,它不会像答案中那样以无限循环阻塞整个浏览器。 jQuery UI 对话框的选项
modal
只是阻止当前页面。这是代码:
您可以这样使用它:
DEMO
The duplicate is not really useful indeed. I'm sorry for that.
Based on this answer, this what I would do:
create a function that will create a basic modal dialog with a message and OK/Cancel buttons
accept two callbacks for both buttons executed when they are clicked
The benefit is that it does not block the whole browser with an infinite loop like in the answer. The option
modal
of the jQuery UI dialog simply blocks the current page.Here's the code:
And you can use it this way:
DEMO