javascript 单击 <a href="#"></a> 时不想转到页面顶部
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7529114/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
when clicking <a href="#"></a> don't want to go to top of page
提问by Ozkan
Possible Duplicate:
Href=“#” Don't Scroll
可能重复:
Href="#" 不要滚动
I have the following html in my code
我的代码中有以下 html
<a href="#">link</a>
<a href="#">link</a>
When i click on 'link', then my page goes automatically to top what is very normal as you all know. But i want that my page stays where it is when clicked on that link.
当我点击“链接”时,我的页面会自动转到顶部,这是众所周知的非常正常的事情。但我希望我的页面在点击该链接时保持原样。
Somebody knows a good workaround for this?
有人知道一个好的解决方法吗?
PS: I can't change the html, it has to be a hyperlink
PS:我不能改变html,它必须是一个超链接
Thanks.
谢谢。
回答by devtut
You can use like this <a href="javascript:;">link</a>
你可以这样使用 <a href="javascript:;">link</a>
回答by Mika Andrianarijaona
If you can edit the a tag, you can put :
如果您可以编辑 a 标签,则可以输入:
<a href="#stay_here" name="stay_here">link</a>
回答by Ashnur
First of all, you can change the html if you apply cursor:pointer
(from CSS) on it.
For your problem, you need event.returnValue = false;
in ie and event.preventDefault();
for the browsers.
首先,如果您cursor:pointer
在其上应用(从 CSS),您可以更改 html 。对于您的问题,您需要event.returnValue = false;
在 ie 和event.preventDefault();
浏览器中。
See this too: Href="#" Don't Scroll
也请参阅:Href="#" 不要滚动