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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745401639a4626131.html
评论列表(0条)