我有一个名为submit的按钮,当我点击这个按钮时,我收到了一个确认框.如果我点击确认框上的确定按钮,我会看到一个对话框.但是,如果我取消此对话框并尝试再次执行此操作,我无法看到对话框.
HTML看起来像这样
<input type="submit" id="btnSubmit" class="button" value="<%= OsflAdminResources.Text_Users_Permanently_Delete_Selected_Users %>"
onclick="return validate();" />
Run Code Online (Sandbox Code Playgroud)
jQuery是: -
function validate()
{
if(confirm("<%= OsflAdminResources.Text_Delete_Warning_Popup_Message %>"))
{
dialog();
return false;
}
else
{
return false;
}
}
function dialog()
{
$("#dialogToShow").dialog({
title: "Confirm Password",
closeText: "Cancel",
show:"slide",
resizable: false,
modal: true,
open: function(ev, ui){
$('.ui-widget-overlay').stop().animate({"opacity": "0.40"}, 1480);
},
close: function(ev, ui){
$('.ui-widget-overlay').stop().animate({"opacity": "0"}, 1480);
}
});
return false;
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮我解决这个问题吗?
问题是,您尝试第二次重新初始化对话框.这是不可能的.将对话框分配给变量并使用此引用打开对话框.另外一定要设置autoOpen: false.
请尝试以下方法:
var $dialog = null;
function dialog()
{
// create dialog if not done already
if (!$dialog) {
$dialog = $("#dialogToShow").dialog({
title: "Confirm Password",
closeText: "Cancel",
show:"slide",
resizable: false,
modal: true,
autoOpen: false, // this is important! prevent auto open
open: function(ev, ui){
$('.ui-widget-overlay').stop().animate({"opacity": "0.40"}, 1480);
},
close: function(ev, ui){
$('.ui-widget-overlay').stop().animate({"opacity": "0"}, 1480);
}
});
}
// use the reference to the dialog and call open.
$dialog.dialog('open');
return false;
}
Run Code Online (Sandbox Code Playgroud)