简体   繁体   English

为什么要使用href =“javascript:void()?

[英]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.

相关问题 为什么使用&#39;href =“javascript:void(0);”&#39;而不是更友好的用户? - Why use 'href=“javascript:void(0);”' instead of something more user friendly? 我应该为 JavaScript 链接使用哪个“href”值,“#”还是“javascript:void(0)”? - Which "href" value should I use for JavaScript links, "#" or "javascript:void(0)"? 使用 Python 单击 javascript:void(0) 类型的 href 以检索 tar 文件 - Use Python to click href of type javascript:void(0) to retrieve tar file 使用vba触发html锚href =“ javascript:void(0)” - Use vba to trigger html anchor href=“javascript:void(0)” href =“ javascript :;”或href =“ javascript:void(0)”,有什么区别? - href=“javascript:;” or href=“javascript:void(0)”, the difference? href =“javascript:”vs. href =“javascript:void(0)” - href=“javascript:” vs. href=“javascript:void(0)” php echo href =&#39;javascript:void(0);&#39; - php echo href='javascript:void(0);' 这个href值是否等同于“javascript:void(0)”? - Is this href value equivalent to “javascript:void(0)”? [routerLink] =“” VS href =” javascript:void(0);” - [routerLink]=“” VS href=“javascript:void(0);” 在 href 中使用 javascript 变量出错了 - 为什么? - use javascript variable in href went wrong - why?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM