我试图用 jQueryUI 对话框覆盖默认的确认框,这是我的尝试:
window.confirm = function (message_confirm) {
$(document.createElement('div'))
.attr({ title: 'Please confirm', 'class': 'confirm', 'id': 'dialogconfirm' })
.html(message_confirm)
.dialog({
buttons: { YES: function () { return true; }, NO: function () { $(this).dialog('close'); } },
close: function () { $(this).remove(); },
draggable: true,
modal: true,
resizable: false,
width: 'auto',
hide: { effect: "fade", duration: 300 },
});
};
这是因为一旦该脚本运行,调用常规 confirm
会显示 jQueryUI 对话框,但是,YES
选择不起作用。我有一个如下所示的 ajax 调用:
if (confirm("Are you sure you want to delete this user?"))
{
alert("test");
//ajax call
}
return false;
并且没有出现测试警报。对话框的 NO 选择工作正常。我怎样才能让 YES 起作用?
谢谢。
最佳答案
你可以给函数添加一个回调参数
window.confirm = function (message_confirm, ok_callback)
在 YES 上触发它
buttons: { YES: function () { ok_callback(); }}
稍后继续
confirm("message", function(){
alert('smth');
});
关于javascript - 用于确认的 jQueryUI 对话框替换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38722811/