Jquery mobile - onhashchange问​​题 [英] Jquery mobile - onhashchange issue

查看:114
本文介绍了Jquery mobile - onhashchange问​​题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用中使用 $ .mobile 。我必须创建自己的路由系统。
我在 hashchange 上绑定观察者,并从 location.hash 中提取有趣的数据。
我有一个问题 - jQuery.mobile location.hash 中移除哈希符号斜线(例如从'lalal / #controller / action / param''lalal / controller / action / param'并且 $ .mobile 在黄色框中显示错误加载页面

I am using $.mobile in my app. I must create my own routing system. I bind observer on hashchange and I pull out interesting data from location.hash. I have a problem - jQuery.mobile removes the hash sign from location.hash if it has a slashes ( e.g. from 'lalal/#controller/action/param' to 'lalal/controller/action/param' and $.mobile says in yellow box Error Loading Page.

我首先尝试取消绑定现有的hashchange,但后来页面没有自动加载(我要求的)。

I tried to unbind existing "hashchange" in first, but then pages not load automatically ( what I require ).

如何防止哈希的更改,但是jQuery必须仍然自动加载页面(例如,在元素中声明的ID data-role ='page')。下面是我路由器类的一个片段:( Router.load 不会改变 location.hash

How to prevent changes of hash, but that jQuery must still load the page automatically( e.g. by its ID declared in element having data-role='page')? . Below is a fragment of my router class: ( Router.load doesn't change location.hash )

__construct: function() {   

        var that = this; 
        $( window ).bind( "hashchange" , function( e ) {
            //e.stopImmediatePropagation()
            that.load( this.location.hash  ); 

        });  
    }


推荐答案

我相信你正在反抗jQuery Mobile中的pushState插件在Beta 3中添加(我相信)。您可以使用以下代码禁用此插件(在包含jQuery Mobile JavaScript文件之前使用):

I believe you are fighting against the "pushState" plugin in jQuery Mobile added in Beta 3 (I believe). You can disable this plugin with the following code (used before you include the jQuery Mobile JavaScript file):

$(document).on('mobileinit', function () {
    $.mobile.pushStateEnabled = false;
});

点击此处的文档(注意pushState插件部分): http://jquerymobile.com/demos/1.0rc3/docs/pages/page-navmodel。 HTML

Check-out the documentation here (notice the "pushState Plugin" section): http://jquerymobile.com/demos/1.0rc3/docs/pages/page-navmodel.html

这篇关于Jquery mobile - onhashchange问​​题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆