附加了查询参数的哈希链接是否可以在jQuery Mobile中使用? [英] Should a hash link with a query parameter appended to it work in jQuery Mobile?

查看:84
本文介绍了附加了查询参数的哈希链接是否可以在jQuery Mobile中使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<a href="#page2?golfer=arnoldpalmer"></a>

我只是试过了,所以不起作用. jQuery Mobile似乎摆脱了链接的?golfer = arnoldpalmer部分(您可以通过查看源代码看到它). 有任何解决方法或解决方案吗?

I just tried it and it doesn't work. jQuery Mobile seems to get rid of the ?golfer=arnoldpalmer part of the link (you can see this via view source). Any workarounds or solutions?

这是因为标准是我们不能在页面哈希链接后面放置参数?

Is this because the standards are that we cannot put parameters behind page hash links?

推荐答案

正如@zyrex指出的那样,存在纯" jQuery移动解决方案.

As @zyrex pointed out, there are "pure" jQuery mobile solution.

另一种流行的解决方案是依靠骨干路由器,它提供了URL中参数的现成解析.

Another popular solution is to rely on Backbone Routers which provide out of the box parsing of parameters in URLs.

您应该使用此功能,必须使用以下方法在JQuery Mobile中停用标签拦截:

Should you use this, you must deactivate hashtag interception in JQuery Mobile using

$( document ).on( "mobileinit",
    // Set up the "mobileinit" handler before requiring jQuery Mobile's module
    function() {
        // Prevents all anchor click handling including the addition of active button state and alternate link bluring.
        $.mobile.linkBindingEnabled = false;

        // Disabling this will prevent jQuery Mobile from handling hash changes
        $.mobile.hashListeningEnabled = false;
    }
)

在路由器中创建路由

 routes: {

     "": "start",

     "page2/:golfer": "gotopage2"
 }

然后在您的处理程序中进行JQM导航

And do JQM navigation in your handler

gotopage2: function( golfer ) {

    //do something with golfer

    //show JQM page
    $.mobile.pageContainer.pagecontainer( "change", "#page2")                    
}

这篇关于附加了查询参数的哈希链接是否可以在jQuery Mobile中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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