如何在 jquery mobile 中初始化页面?pageinit 没有触发 [英] How to initialize pages in jquery mobile? pageinit not firing

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

问题描述

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

<身体><script type="text/javascript" charset="utf-8" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></脚本><script type="text/javascript" charset="utf-8" src="http://code.jquery.com/mobile/1.0b3/jquery.mobile-1.0b3.min.js"></脚本><div data-role="page" id="myPage">测试

<脚本>$("#myPage").live('pageinit',function() {alert("这永远不会发生");});

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

---- 更新----

错误在 JQM 问题跟踪器中标记为已关闭".显然,对于这是否正常工作存在不同意见.

解决方案

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

<div id="indexPage" data-role="page"><script type="text/javascript">$("#indexPage").live('pageinit', function() {//在这里做点什么...});

使用 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 没有触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆