href must not reload

▼魔方 西西 提交于 2019-12-20 11:03:32

问题


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?

Thanks ;)


回答1:


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.




回答2:


Just add javascript:void(0) in href you will get..

<a href="javascript:void(0)">Link</a>



回答3:


I think javascript:; also works.

<a href="javascript:;">Link</a>


来源:https://stackoverflow.com/questions/18605563/href-must-not-reload

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!