【问题标题】:JQuery Mobile how to run script only once on pageinitJQuery Mobile如何在pageinit上只运行一次脚本
【发布时间】:2011-12-16 09:31:47
【问题描述】:

我遇到了 jquery mobile 和嵌套列表的问题。当我第一次加载页面时它看起来很棒,但是当我在 jquery 移动列表中导航时它不会运行脚本,因为它在 document.ready() 中

我找到了使用

的解决方案
$('[data-role="page"]').live('pageinit', function (event) {
}

但是脚本运行了 6 次,因为我在网站上有 6 个 data-role="page"。我怎样才能设法在“pageinit”上只运行一次脚本。

我正在尝试操作一个页面,因此我不想只选择第一个页面/只运行一次代码。

【问题讨论】:

    标签: jquery jquery-mobile document-ready page-init


    【解决方案1】:

    不确定这是否是您的问题,但这是我的问题。两件事情。首先,确保您没有多次意外引用 jQuery Mobile javascript 文件。这会导致坏事发生。其次,您可能希望将其添加到您的第一页:

    $(document).bind("mobileinit", function () {
        // As of Beta 2, jQuery Mobile's Ajax navigation does not work in all cases (e.g.,
        // when navigating from a mobile to a non-mobile page), hence disabling it.
        $.mobile.ajaxEnabled = false;
    });
    

    然后你会想要使用:

    $("#pageName").bind("pageinit", function (event) {
       // Start code here
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-21
      • 1970-01-01
      相关资源
      最近更新 更多