我已经看到了这个类似的closing jquery modal dialog is slow问题,但在此示例中,它不使用buttons
属性,这是我的问题。如何在调用函数后不使用$(this).dialog(“close”)关闭对话框?
请参阅此FIDDLE了解演示
var begin = new Date();
$(function() {
$( "#dialog-confirm" ).dialog({
resizable: false,
height:140,
modal: true,
buttons: {
"Delete all items": function() {
// $( this ).dialog( "close" ); too slow
foo();
},
Cancel: function() {
$( this ).dialog( "close" ); too slow
foo();
}
}
});
});
答案 0 :(得分:0)
见下面的代码,希望它有所帮助。
var begin = new Date();
$(function() {
$("#dialog-confirm").dialog({
resizable: false,
height: 140,
modal: true,
buttons: {
"Delete all items": function() {
// $( this ).dialog( "close" );
foo();
},
Cancel: function() {
foo(clsPopUp);
}
}
});
});
function clsPopUp() {
$("#dialog-confirm").dialog("close");
}
function foo(callback) {
var end = new Date();
alert((end - begin) / 1000);
callback();
}
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<body>
<div id="dialog-confirm">
<p>Are you sure?</p>
</div>
</body>
答案 1 :(得分:0)
尝试:
$( "#dialog-confirm" ).parent().hide();
而不是:
$( this ).dialog( "close" );