使用jQuery停止默认的标签行为 [英] Stop default hashtag behavior with jquery

查看:74
本文介绍了使用jQuery停止默认的标签行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码将#标签附加到url的末尾.这样,有人可以复制该网址,然后将其带回该页面,并且可以看到某些div.

I'm using the following code to append a hashtag to the end of a url. That way someone can copy that url and take them back to that page, with certain divs visable.

$("a.live").click(function() {
    window.location.hash = 'live'; 
    $("#live).slideDown();
});

在此示例中,我有一个名为"live"的div,当单击链接时,它将向下滑动,并将"#live"添加到URL中.然后,我有代码可以在加载页面以显示正确的div时检查哈希标签.

In this example I have a div called 'live', that would slideDown when a link is clicked, and '#live' added to the url. Then I have code that checks the hash tags when the page is loaded to show the proper divs.

我的问题是,如何防止浏览器在被调用后跳到实时" div?我不希望页面向下滚动到div,只希望它打开并附加#标签,这样人们就可以复制它并返回显示该div的页面.

My problem is, how do I prevent the browser from jumping to the 'live' div once it's called? I don't want the page to scroll down to the div, just want it opened and the hashtag appended so a person could copy it and come back to that page with that div showing.

有什么秘诀吗?

谢谢!

推荐答案

尝试一下:

$("a.live").click(function() {
    window.location.hash = 'live'; 
    $("#live").slideDown();
    return false; // this will prevent default action
});

这篇关于使用jQuery停止默认的标签行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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