jQuery的 - 在设置URL的哈希后 [英] jquery - setting the url after the hash

查看:105
本文介绍了jQuery的 - 在设置URL的哈希后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想,如果我可以点击一个链接带班查询,并将它的id属性来散后。例如,一个链接,看起来像这样:

I'd like if I could click a link with class "query" and have it's id attribute come after the hash. For example, a link that looks like this:

< A HREF =#ID =成员级=查询>成员< / A>

当点击将改变从 example.com/users 链接直接 example.com/users#members

When clicked would change the url from example.com/users to example.com/users#members.

下面是我的code到目前为止:

Here's my code so far:

$('.query').click(function(event){
    event.preventDefault();
    window.location.href = $(this).attr('id');
});

现在点击链接只是移动的网址 example.com/members

推荐答案

设置属性:

window.location.hash = $(this).attr('id');

这篇关于jQuery的 - 在设置URL的哈希后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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