jQuery确认暂停脚本执行的框
我正在寻找标准对话框的jquery /漂亮的替代品。 jQUery UI有一个很好的,但它不会暂停脚本执行以等待像confirm()那样的响应。 下面的演示应该显示两个显示前一个确认框选项的div,但是jquery对话框不会导致脚本等待。
http://jsfiddle.net/EvilAmarant7x/r7Ur5/
我特别需要一些导致脚本暂停的东西。
谢谢
您以错误的方式使用对话框
你应该这样做
$("#dialog-confirm").dialog({ resizable: false, height: 140, modal: true, buttons: { Proceed: function() { call_true_function(); $(this).dialog("close"); }, Cancel: function() { call_false_function() $(this).dialog("close"); } } });
或类似的东西
**编辑**
这样的事情呢?
count = 0; $("#dialog-confirm").dialog({ resizable: false, height: 140, modal: true, buttons: { Proceed: function() { proceed(); $(this).dialog("close"); }, Cancel: function() { $(this).dialog("close"); } } }); function proceed(){ if (count != 10){ $("#dialog-confirm").dialog('open'); }else{ $('body').append("Yes was selected " + count + " times!"); } }
不幸的是,如果您使用自定义确认/模态窗口,则无法进行此操作。 您将不得不使用回调或选择使用1.5引入的新延迟对象。
使用deferred看起来像这样:
var dfd = new $.Deferred(); $("#dialog-confirm").dialog({ resizable: false, height: 140, modal: true, buttons: { Proceed: function() { dfd.resolve('Success!'); $(this).dialog("close"); }, Cancel: function() { dfd.reject('Uh-oh!'); $(this).dialog("close"); } } }); dfd.then(function() { // perform next action when user clicks proceed }); dfd.fail(function() { // perform some action when the user clicks cancel });