制作不执行任何操作(实际上不执行任何操作)的HTML链接 [英] Make a HTML link that does nothing (literally nothing)
问题描述
我想要一个不执行任何操作的链接.我不想要这个:
I want a link that does nothing. I don't want this:
<a href="#">
因为URL变为something.com/whatever/#
.
我想要链接的唯一原因是,使用户可以看到他们可以单击文本.使用JavaScript来执行某些操作,因此我不需要将该链接放到任何地方,但是我需要使它看起来像一个链接!
The only reason I want a link is so the user can see that they can click on the text. JavaScript is being used to perform some action so I don't need the link to go anywhere but I need it to look like a link!
我可以使用一些数据属性,并告诉我CSS使元素看起来像链接(如果它们具有此属性,但是看起来有些过分了.
I could use some data attribute and tell me CSS to make elements look like links if they have this attribute but it seems a bit overkill.
推荐答案
以下内容将阻止您的href被运行
The following will prevent your href from being ran
<a href="#" onclick="return false;">
如果您使用的是jQuery,则可以使用 event.preventDefault()
If you are using jQuery, event.preventDefault()
can be used
这篇关于制作不执行任何操作(实际上不执行任何操作)的HTML链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!