href不得重新加载 [英] href must not reload
问题描述
我正在测试以下链接:
<a href="#">Link</a>
但是,正如预期的那样,它重新加载了我的当前页面.如何防止它重新加载页面,但保持分配给它的 -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?
谢谢;)
推荐答案
如果您不希望它表现为链接,请不要使用链接标记.这样做会损害页面的可访问性,而您不希望那样做.除了浏览器(想想屏幕阅读器)以外,还有其他浏览网站的方式,这依赖于页面元素的语义.如果您只是想应用样式,请使用span
.
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.
如果您仍要使用锚,可以使用此-
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.
这篇关于href不得重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!