【发布时间】:2016-03-01 08:12:15
【问题描述】:
我为“pagebeforechange”设置了以下监听器(与 jQuery Mobile 文档自己的代码非常相似)和主页上调用 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 由于边缘点击而被注册两次,但这没有任何意义,因为它依赖于实际的页面更改。
【问题讨论】:
-
您是在运行多页还是单页布局? jquerymobile.com/demos/1.0/docs/pages/index.html 我问的原因是你绑定到 $(document) 而不是 pageId
-
多页布局 - "showProduct()" 方法将信息加载到第二页,然后转换。
-
我想知道既然你绑定了 $(document) 它被多次调用,你可以只使用 pageId 来测试吗?
-
就是这样 - 还有一个搜索页面,即使它有不同的页面 ID 并且不是“活动的”,它也会导致它调用两次。不知道为什么非活动页面导致事件注册,但这是一个完全不同的问题。非常感谢。盯着它看了几个小时后有点空白:-)。如果你想拼凑一个答案,我很乐意给你一个正确的答案。
标签: jquery-mobile