JQuery确认对话框
可能重复:
是或否使用jQuery确认框
我在这里看到很多关于jQuerys标准确认对话框替换的例子,但是不了解它们中的任何一个。
如果我想使用jQuery或jQueryUI弹出确认对话框。 我该怎么做并检索用户点击的按钮?
当然必须有一种简单的方法来设置一个像alert("Something!");
一样的确认对话框alert("Something!");
命令。
添加两个按钮并在yes
或no
设置回叫function?
试试这个
$('').appendTo('body') .html('Yes or No?
') .dialog({ modal: true, title: 'message', zIndex: 10000, autoOpen: true, width: 'auto', resizable: false, buttons: { Yes: function () { doFunctionForYes(); $(this).dialog("close"); }, No: function () { doFunctionForNo(); $(this).dialog("close"); } }, close: function (event, ui) { $(this).remove(); } });
小提琴
您可以使用jQuery UI并执行类似的操作
HTML:
Are you sure about this?
使用Javascript:
$("#dialog").dialog({ autoOpen: false, modal: true, buttons : { "Confirm" : function() { alert("You have confirmed!"); }, "Cancel" : function() { $(this).dialog("close"); } } }); $("#callConfirm").on("click", function(e) { e.preventDefault(); $("#dialog").dialog("open"); });
您是否尝试过使用官方JQueryUI实现 (不仅仅是jQuery):