我试图使用一个jquery对话框作为“请等待”的消息。这通常是可行的,但是这个特定的任务是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');
});
摆弄我
有什么建议吗?
发布于 2018-03-29 17:06:19
您可以使用setTimeout(fn, 0);
请求执行。正如您在示例中所看到的那样,"hello“出现在"hello”之前。
$("#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');
});
<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">
https://stackoverflow.com/questions/49561202
复制相似问题