[英]Jquery mobile - onhashchange issue
我在我的應用程序中使用$.mobile
。 我必須創建自己的路由系統。 我在hashchange
上綁定了觀察者,並從location.hash
提取了有趣的數據。 我有一個問題jQuery.mobile
如果有斜線(例如,從'lalal/#controller/action/param'
到'lalal/controller/action/param'
,則從location.hash
刪除哈希符號,而$.mobile
在黃色框Error Loading Page
。
我嘗試首先取消綁定現有的“ hashchange”,但隨后頁面不會自動加載(我需要)。
如何防止哈希值發生變化,但是jQuery必須仍然自動加載頁面(例如,通過在具有data-role='page'
元素中聲明的ID)? 。 以下是我的路由器類的片段:( Router.load
不會更改location.hash
)
__construct: function() {
var that = this;
$( window ).bind( "hashchange" , function( e ) {
//e.stopImmediatePropagation()
that.load( this.location.hash );
});
}
我相信您正在與Beta 3中添加的jQuery Mobile中的“ pushState”插件進行對抗(我相信)。 您可以使用以下代碼(在包含jQuery Mobile JavaScript文件之前使用)禁用此插件:
$(document).on('mobileinit', function () {
$.mobile.pushStateEnabled = false;
});
在此處簽出文檔(請注意“ pushState插件”部分): http : //jquerymobile.com/demos/1.0rc3/docs/pages/page-navmodel.html
在包含jquery之后且包含jquery.mobile-1.xyjs 之前的html中添加:
<script>
$(document).bind("mobileinit", function(){
$.mobile.pushStateEnabled = false;
$.mobile.ajaxEnabled = false;
$.mobile.hashListeningEnabled = false;
});
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.