我正在尝试使用jquery dialog作为“请稍候”消息。这通常有效,但是这个特殊的任务是CPU密集型的并且在打开异步对话框之前冻结。我已尝试将任务附加到对话框中的“打开”事件,但在对话框打开之前打开事件和“焦点”事件
$("#dialogbox").dialog({
autoOpen:false,
modal:true,
title: "Use of Open event",
width:300,
open: function( event, ui ) {
alert('hello open');
},
focus: function( event, ui ) {
alert('hello focus');
}
});
$('#mybutt').click(function() {
$('#dialogbox').html('<h2>Watch this</h2>An alert box should have opened');
$('#dialogbox').dialog('open');
});
有什么建议吗?
答案 0 :(得分:1)
您可以使用setTimeout(fn, 0);
重新执行执行。正如您在示例中所看到的那样&#34;你好焦点&#34;出现之前&#34;你好打开&#34;。
$("#dialogbox").dialog({
autoOpen:false,
modal:true,
title: "Use of Open event",
width:300,
open: function( event, ui ) {
setTimeout(function(){alert('hello open');}, 0);
},
focus: function( event, ui ) {
alert('hello focus');
}
});
$('#mybutt').click(function() {
$('#dialogbox').html('<h2>Watch this</h2>An alert box should have opened');
$('#dialogbox').dialog('open');
});
&#13;
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<div id="dialogbox"></div>
<input id="mybutt" type="button" value="Click Me">
&#13;