Pageinit上的jQuery移动弹出窗口 [英] jQuery mobile popup on pageinit
本文介绍了Pageinit上的jQuery移动弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望在页面加载后立即打开一个弹出窗口,但似乎卡在了转盘上.
I want a popup to open as soon as the page loads but seem to be getting stuck with the spinning wheel.
这里有个提琴手来演示这个问题,将不胜感激.
Here is a fiddler to demonstrate the problem any help would be appreciated.
http://jsfiddle.net/Ohpyx/UGfXG/
我正在使用的代码是:
$(document).live('pageinit',function(event){
$('#popupBasic').popup('open');
})
推荐答案
这对我有用:
$(document).on('pageinit', '.ui-page',function(event){
setTimeout(function () {
$('#popupBasic').popup('open');
}, 0);//Note the comment below from @Taifun.
})
您遇到了争用情况,因此将弹出代码放置在队列的末尾.
You had a race condition and this places the popup code at the end of the queue.
这是一个演示: http://jsfiddle.net/UGfXG/6/
注意:我将.live()
替换为.on()
(委托的风味),因为前者已从jQuery 1.7开始贬值.
Note: I replaced .live()
with .on()
(the delegated flavor) as the former has been depreciated as of jQuery 1.7.
这篇关于Pageinit上的jQuery移动弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文