[英]Jquery Button Dialog Box not Closing Immediately when Click
I have a button called "Show All", when user click it, it will pop up a window to confirm whether user wants to show all entities. 我有一个名为“显示全部”的按钮,当用户单击它时,它将弹出一个窗口,以确认用户是否要显示所有实体。 I am using Jquery for this dialog box, I have:
我为此对话框使用Jquery,我有:
function showAll() {
$("#" + showAllDiv).show();
$("#" + showAllDiv).dialog( {
title: XXX,
height: XXX,
width: XXX,
modal : true,
buttons: {
"Yes": function () {
$(this).dialog("close");
addLoadingFn(); // it will show a "please wait..." dialog
heavyDutyWorkFn(); //a function to get all data and show on the pop up HTML window;
deleteLoadingFn(); // it will close the "please wait..." dialog
},
Cancel: function() {
$(this).dialog("close");
}
}
});
$("#" + showAllDiv).html(You sure to show all?)
}
The problem is, when I click Yes, the dialog does not close immediately. 问题是,当我单击“是”时,对话框不会立即关闭。 It will still stay for a while until the "heavyDutyWorkFn()" finish its work.
它仍然会保留一段时间,直到“ heavyDutyWorkFn()”完成工作为止。 In another world, after click "Yes", $(this).dialog("close") will not close, until heavyDutyWorkFn() finish showing all data.
在另一个世界中,单击“是”后,$(this).dialog(“ close”)将不会关闭,直到heavyDutyWorkFn()完成显示所有数据为止。
Does anybody know what happened? 有人知道发生了什么吗? Any help will be greatly appreciated.
任何帮助将不胜感激。 Thank you!
谢谢!
You can run heavyDutyWorkFn()
asynchronously with setTimeout()
, so it doesn't delay the rest of the script. 您可以与
setTimeout()
heavyDutyWorkFn()
异步运行heavyDutyWorkFn()
,因此不会延迟脚本的其余部分。
function showAll() {
$("#" + showAllDiv).dialog( {
title: XXX,
height: XXX,
width: XXX,
modal : true,
buttons: {
"Yes": function () {
$(this).dialog("close");
addLoadingFn(); // it will show a "please wait..." dialog
setTimeout(function() {
heavyDutyWorkFn(); //a function to get all data and show on the pop up HTML window;
deleteLoadingFn(); // it will close the "please wait..." dialog
}, 1);
},
Cancel: function() {
$(this).dialog("close");
}
}
}).html("You sure to show all?")
}
BTW, it's not necessary to call .show()
, since .dialog()
automatically shows the dialog (unless you use autoOpen: false
). 顺便说一句,没有必要调用
.show()
,因为.dialog()
自动显示对话框(除非您使用autoOpen: false
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.