admin管理员组文章数量:1426484
What is the reason for using javascript:{}
in the code below. Is it similar to href="javascript:"
or href="javascript:void(0)"
?
<a href="javascript:{}">This is an example</a>
What is the reason for using javascript:{}
in the code below. Is it similar to href="javascript:"
or href="javascript:void(0)"
?
<a href="javascript:{}">This is an example</a>
Share
Improve this question
edited Sep 15, 2018 at 18:16
node_modules
4,9356 gold badges25 silver badges38 bronze badges
asked Sep 15, 2018 at 18:11
Jim_JoatJim_Joat
717 bronze badges
2
- Sort of - yes, it's the same as those. It disables the link. – VLAZ Commented Sep 15, 2018 at 18:14
- My friend your answer is here: stackoverflow./a/7755207/10325004 – Akshay Jain Commented Sep 15, 2018 at 18:21
2 Answers
Reset to default 5Let hyperlink look like a link but didn't link anything.
<a href="javascript:{}">This is an example</a>
if you remove href
attribute, that a
tag will be normal text.
It makes a button act like a link, but lets you execute custom JS code instead of linking to a webpage.
For example:
<a href="javascript:{ document.write('hi u just pressed me');}"> Press me pls </a>
acts like
<div onclick="doOnClick()"> Press me pls </a>
<script>
function doOnClick(){ document.write('hi u just pressed me'); }
</script>
but the browser treats the former like a link.
本文标签: htmlWhat does hrefjavascript doStack Overflow
版权声明:本文标题:html - What does href=javascript:{} do? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745401638a2657067.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论