zoukankan      html  css  js  c++  java
  • Jquery Mobile中pageinit等函数执行两次的问题【终极解决】

    当禁用了jqueryMobile的ajax后,初始化函数如pageinit和pageshow等函数,都会执行两次。document.ready函数也会执行两次。

    当然我们可以用一个变量记录是否已经执行,如果已经执行就不再执行第二次,但终究这不是最终办法。

        var loaded = false;//防止执行重复
    
        $(document).ready(function () {
            if (!loaded) {
    
                //do something
                 loaded = true;
            }
        });
    
        $(document).live('pageshow', function () {
    
            if (!loaded) {
    
                //do something
                loaded = true;
            }
        })

    ps:jqM是强烈建议,把原来的ready函数换成pageinit函数。
    解决避免执行两次的办法是:在body中加如data-role="page",标记当前文档是page对象。

    jqm中一个document中有多个page对象。当然也可以将div标记为page对象。

    以下是原文:

    The docs say very prominently not to use "$(document).ready()" any more but to use "pageInit()" instead.
    So I am trying to change to pageInit() and also change from "window.open" to "pageChange".
     
    I understand that to do this all pages should have the same header that references all the sources needed by any of the pages.
    And I understand the page specific code has to be in the <div data-role="page"> element.
  • 相关阅读:
    npx 是什么?
    JavaScript 的内置对象和浏览器对象
    JS构造函数new的过程
    git 设置和取消代理
    npm配置镜像、设置代理
    SQL 注入攻击案例
    javascript:void(0);的含义以及使用场景
    让所有网页图片跳起舞来的代码
    针对Web的攻击技术
    网站常见的鉴权认证方式有哪几种?
  • 原文地址:https://www.cnblogs.com/langu/p/3914987.html
Copyright © 2011-2022 走看看