Javascript 检测jquery mobile上的changepage

Javascript 检测jquery mobile上的changepage,javascript,jquery,jquery-mobile,Javascript,Jquery,Jquery Mobile,使用.changePage()函数更改页面时,如何执行代码 例如,我使用以下代码: $.mobile.changePage( "index.html#pageTwo" ); 当第二页加载时,我想这样做: alert("Test"); 在你的。。这样说: // Jquery loaded here <script> $(document).on("pageshow","#pageTwo", function() { alert("Test"); } &l

使用
.changePage()
函数更改页面时,如何执行代码

例如,我使用以下代码:

$.mobile.changePage( "index.html#pageTwo" );
当第二页加载时,我想这样做:

alert("Test");
在你的。。这样说:

// Jquery loaded here <script> $(document).on("pageshow","#pageTwo", function() { alert("Test"); } </script> // jquery mobile loaded here //Jquery在这里加载 $(文档)。在(“pageshow”、“#pageTwo”,函数()上{ 警报(“测试”); } //jquerymobile在这里加载 注:

  • 上面的代码必须放在Jquery加载之后和Jquery mobile加载之前

  • 上面的代码示例假定index.html页面包含至少具有data role=“page”和id=“pageTwo”属性的div:

    这是第二页的内容

  • Jquery mobile只解析/使用加载的第一个页面的..部分中的任何内容!要确保加载移动站点中所有页面所需的所有代码,无论用户首先到达哪个页面,您都应该按照以下方式构建所有页面:

  • //加载jquery //所有jquery移动页面事件绑定都放在这里 //加载jquerymobile 这是第一页的内容 这是第二页的内容
    有很多事件,您使用的是哪个版本?我使用的是版本1.4.2检查这个jqmtricks.wordpress.com/2014/03/26/jquery-mobile-page-events/可能重复的
    mobileinit
    应该只放在JQM之前。其余的应该在JQM之后加载。请注意,
    pageshow
    以及页面事件从1.4开始都是不推荐的。)@奥马尔说得很好。这是我在JQM 1.3.1中使用的结构,它可以正常工作。 <html> <head> <script src="path/to/jquery.js"> // load jquery <script src="path/to/common.js"> // all jquery mobile page event bindings are placed in here <script src="path/to/jquery_mobile.js"> // load jquery mobile </head> <body> <div data-role="page" id="pageOne"> This is page one content </div> <div data-role="page" id="pageTwo"> This is page two content </div> </body> </html>