我试图重写与jQueryUI的对话框中的默认确认框,这里是我的尝试: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工作?
谢谢。
任何错误?尝试与console.log而不是警报? console.log是否在“YES:”函数中工作(用return true替换)? – ggzone
@ggzone没有错误。用'console.log(“对话框被点击”)代替'return true',并且当我点击是时它在控制台上正确显示。 console.log代替警报也没有出现(与原始警报测试相同的行为)。 – ITWorker
好吧,你想要一个回调函数。已经有一个很好的答案如何做到这一点 – ggzone