[英]Why use href="javascript:void()?
Reading this question : What does "javascript:void(0)" mean? 阅读这个问题: “javascript:void(0)”是什么意思? I can understand why <a href="javascript:void(0)"
is used - in order to prevent a page redirection. 我可以理解为什么使用<a href="javascript:void(0)"
- 以防止页面重定向。
I have come across this code : 我遇到过这段代码:
<a id="myId" href="javascript:void()"
onclick="removePopup()">Close</a>
The operator void
does not take any parameter in this case. 在这种情况下,operator void
不接受任何参数。 Is this a bug ? 这是一个错误吗?
Yes, it's a bug. 是的,这是一个错误。 The browser will throw a syntax error when the link is clicked, unless the removePopup()
function stops the default action. 单击链接时,浏览器将抛出语法错误,除非removePopup()
函数停止默认操作。 (If the function does that, it might explain why the developer didn't notice it.) (如果函数执行此操作,则可能解释了开发人员没有注意到它的原因。)
> void()
SyntaxError: Unexpected token )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.