jquery-mobile – jQuery Mobile“pagebeforechange”被调用两次

我为“pagebeforechange”设置了以下监听器(非常类似于jQuery Mobile Documentation自己的代码),并在主页上调用一个名为 http://localhost/#product?id=255979链接
//Bind Listener for Product Details
$(document).bind( "pagebeforechange",function( e,data ) {
    //Only Run If Site is Initialized
    if( ajaxSite.options.initialized ) {
        if ( typeof data.toPage === "string" ) {
            var u = $.mobile.path.parseUrl( data.toPage ),pl = /^#product/;

            if ( u.hash.search(pl) !== -1 ) {
                console.log("showProduct being called.");
                ajaxSite.showProduct( u,data.options );
                e.preventDefault();
            }
        }
    }
});

当我打开JavaScript控制台并单击链接时,我看到以下内容

showProduct being called.
showProduct being called.

我似乎无法找到任何关于为什么它会被调用两次的事情.我看到其他错误,其中vclicks由于边缘单击而被注册两次,但这没有任何意义,因为它依赖于实际的页面更改.

解决方法

因为您绑定到$(文档)并使用多页面布局

> http://jquerymobile.com/demos/1.0/docs/pages/index.html

我认为jQM多次加载文档(只是一个预感)

切换到使用pageId代替,例如:

$(document).bind( "pagebeforechange",data ) { ...

$('#pageId').bind( "pagebeforechange",data ) { ...

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...