可以将delay()与jQuery UI dialog.open()一起使用吗? [英] Can delay() be used with jQuery UI dialog.open()?
问题描述
我已准备好此代码内联文件
I have this code inline in document ready
if($.cookie('form_seen') == null) {
$("#dialog_form").dialog("open");
}
我知道如何使用setTimeout,如如何延迟自动打开模态对话框窗口JQuery 1.5.x?所以不需要发布一个setTimeout示例。
I know how to use setTimeout like How to Delay automatic opening of Modal Dialog box window in JQuery 1.5.x? so no need to post a setTimeout example.
我想知道我的个人教育,如果我想要正确的语法是什么使用.delay而不是setTimeout
I wondered for my personal education, what the correct syntax would be if I wanted to use .delay instead of setTimeout
if($.cookie('form_seen') == null) {
$("#dialog_form").delay(5000).dialog("open");
}
或类似的
在这种情况下,由于我必须在调用的函数中包装 $(#dialog_form)。dialog(open);
,因此我无法获得什么。通过setTimeout所以不需要关闭或找回$(this),但在其他情况下我可以想象链接更聪明。
非常欢迎评论利弊
In this case it is not obvious what I would gain since I would have to wrap $("#dialog_form").dialog("open");
in the function called by setTimeout so no need for closures or finding $(this) back, but in other situations I can imagine chaining being smarter.
Comments to pros and cons are very welcome
推荐答案
if($.cookie('form_seen') == null) {
$("#dialog_form")
.delay(5000)
.queue(function(next){
$(this).dialog("open");
next(); // take this function out of queue a.k.a dequeue a.k.a notify done
// so the next function on the queue continues execution...
})
}
OR
if($.cookie('form_seen') == null) {
$("#dialog_form")
.delay(5000)
.queue(function(){
$(this)
.dialog("open")
.dequeue(); // take this function out of queue a.k.a dequeue a.k.a notify done
// so the next function on the queue continues execution...
})
}
这篇关于可以将delay()与jQuery UI dialog.open()一起使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!