我下面有一个JavaScript代码:
var alertText = "Hey.";
$("div").remove("#confirmationDialogBox");
$(document.body).append("<div id='confirmationDialogBox'></div>");
$("#confirmationDialogBox").html('');
$("#confirmationDialogBox").dialog({
resizable: false,
height: 140,
title: 'Alert !!',
modal: true,
draggable: false,
zIndex: 99999,
buttons: [{
"class": 'btnModalDisplay',
text: "Ok",
click: function () {
//Calls another function that shows an alert
}}]
}).text(alertText);
我的问题是,当对话框出现并且单击对话框的“确定”时,我必须调用另一个显示警报的函数。但是由于某些原因,当我单击“确定”时,对话框没有关闭并显示警报。有人可以帮助我如何关闭对话框,然后显示警报?
尝试一下:
var alertText = "Hey.";
$("div").remove("#confirmationDialogBox");
$(document.body).append("<div id='confirmationDialogBox'></div>");
$("#confirmationDialogBox").html('');
$("#confirmationDialogBox").dialog({
resizable: false,
height: 140,
title: 'Alert !!',
modal: true,
draggable: false,
zIndex: 99999,
buttons: [{
"class": 'btnModalDisplay',
text: "Ok",
click: function () {
//Calls another function that shows an alert
$( this ).dialog( "close" ); /// add this line to close dialog
}}]
}).text(alertText);
您可以尝试像这样更新点击事件:
$("#confirmationDialogBox").dialog({
...
buttons: [{
"class": 'btnModalDisplay',
text: "Ok",
click: function(e) {
//Calls another function that shows an alert
e.preventDefault();
$('#confirmationDialogBox').dialog('close');
}
}]
});