本文介绍了如何在jquery mobile中初始化页面? pageinit不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在jquery移动页面上初始化对象的正确方法是什么? 事件文档表示使用"pageInit()",但没有该函数的示例,但提供了以下示例绑定到"pageinit"方法(注意大小写差异).但是,在这个简单的测试页面中,我根本看不到事件触发:

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>

我想念什么?我应该补充一点,如果将pageinit更改为另一个事件,例如pagecreate,则此代码有效.

What am I missing? I should add that if you change pageinit to another event like pagecreate this code works.

----更新----

---- UPDATE ----

bug 在JQM问题跟踪器中被标记为已关闭".对于此功能是否正常运行,显然存在不同意见.

This bug is marked as "closed" in the JQM issue tracker. Apparently opinions differ about whether this is working properly or not.

推荐答案

当我在div页中嵌入脚本时,它开始工作:

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>

使用了jQuery Mobile 1.0RC1

Used jQuery Mobile 1.0RC1

这篇关于如何在jquery mobile中初始化页面? pageinit不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-10 22:36