Html href不得重新加载
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18605563/
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
href must not reload
提问by gespinha
I am testing the following link:
我正在测试以下链接:
<a href="#">Link</a>
But, as expected, it reloads my current page. How can I prevent it from reloading the page, but maintaining the -a-tag assigned to it?
但是,正如预期的那样,它会重新加载我的当前页面。如何防止它重新加载页面,但保留分配给它的-a-标签?
Thanks ;)
谢谢 ;)
回答by MD Sayem Ahmed
If you don't want it to behave like a link, then don't use a link tag. Doing so hurt accessibility of a page, and you don't want that. There are other ways of browsing a website than a browser (think about the screen readers), which relies on the semantics of the page elements. Use a span
if you simply want to apply a style.
如果你不希望它表现得像一个链接,那么不要使用链接标签。这样做会损害页面的可访问性,而您不希望这样。除了浏览器(想想屏幕阅读器)之外,还有其他浏览网站的方式,它依赖于页面元素的语义。使用span
,如果你只是想应用样式。
If you still want to use an anchor, you can use this -
如果你还想使用锚点,你可以使用这个——
<a href="#" onclick="return false;">Link</a>
This will prevent your page reloading.
这将阻止您的页面重新加载。
回答by Jagadeesh
Just add javascript:void(0) in href you will get..
只需在 href 中添加 javascript:void(0) 你就会得到..
<a href="javascript:void(0)">Link</a>
回答by Si7ius
I think javascript:;
also works.
我认为javascript:;
也有效。
<a href="javascript:;">Link</a>