问题描述
在 jquery 移动页面上初始化对象的正确方法是什么?事件文档 说使用pageInit()
"没有例子该函数,但给出绑定到pageinit
"方法的示例(注意大小写差异).但是,我在这个简单的测试页面中根本没有看到事件触发:
我错过了什么?我应该补充一点,如果您将 pageinit
更改为另一个事件,例如 pagecreate
此代码有效.
---- 更新----
此错误在 JQM 问题跟踪器中标记为已关闭".显然,对于这是否正常工作存在不同意见.
当我在页面 div 中嵌入脚本时它开始工作:
使用 jQuery Mobile 1.0RC1
What's the right way to initialize objects on a jquery mobile page? The events docs say to use "pageInit()
" with no examples of that function, but give examples of binding to the "pageinit
" method (note case difference). However, I don't see the event firing at all in this simple test page:
<html>
<body>
<script type="text/javascript" charset="utf-8" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8" src="http://code.jquery.com/mobile/1.0b3/jquery.mobile-1.0b3.min.js"></script>
<div data-role="page" id="myPage">
test
</div>
<script>
$("#myPage").live('pageinit',function() {
alert("This never happens");
});
</script>
</body>
</html>
What am I missing? I should add that if you change pageinit
to another event like pagecreate
this code works.
---- UPDATE ----
This bug is marked as "closed" in the JQM issue tracker. Apparently opinions differ about whether this is working properly or not.
It started working when I embedded script within page div:
<body>
<div id="indexPage" data-role="page">
<script type="text/javascript">
$("#indexPage").live('pageinit', function() {
// do something here...
});
</script>
</div>
</body>
Used jQuery Mobile 1.0RC1
这篇关于如何在 jquery mobile 中初始化页面?pageinit 没有触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!