首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Jquery对话框afterOpen事件

Jquery对话框afterOpen事件
EN

Stack Overflow用户
提问于 2018-03-29 16:41:28
回答 1查看 278关注 0票数 0

我试图使用一个jquery对话框作为“请等待”的消息。这通常是可行的,但是这个特定的任务是CPU密集型的,并且在异步对话框打开之前冻结。我尝试将任务附加到对话框中的“打开”事件,但在对话框打开之前将打开事件和“焦点”事件消防。

代码语言:javascript
运行
复制
$("#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');
});

摆弄我

有什么建议吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-29 17:06:19

您可以使用setTimeout(fn, 0);请求执行。正如您在示例中所看到的那样,"hello“出现在"hello”之前。

代码语言:javascript
运行
复制
$("#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');
});
代码语言:javascript
运行
复制
<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">

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49561202

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档