为什么使用`javascript:void(0)`而不是`javascript:`作为href做什么占位符? [英] Why use `javascript:void(0)` instead of `javascript:` as an href do nothing placeholder?
问题描述
我曾见过 href =javascript:void(0)
,并且我看到 href =javascript:;
是否有任何理由我不会仅仅使用 href =javascript:
来代替?
编辑:让我清楚:我将它与 onclick
结合,并且不反对使用 return false
如果有必要使用替代方案。当然,这只是在替代方案比 javascript:更好的情况下。
另外,我还没有看到第一段中显示的问题(显然我认为)的答案。 谢谢,大卫。 :)
我曾见过
没有回答您的问题,但可能会更轻在它上面,当在href =javascript:void(0)
我已经看到href =javascript:;
是否有任何理由我不会使用href =javascript:
改为href
中使用脚本时,像netscape这样的浏览器的一些早期版本出现问题。
void
操作符几乎只是强制点击不做任何事。
现在,浏览器正确执行伪网址,您可以安全地使用
javascript:;
。I have seen
href="javascript:void(0)"
and I have seenhref="javascript:;"
Is there any reason I would not just usehref="javascript:"
instead?Edit: Let me make it clear: I am combining this with an
onclick
and have no objection to usingreturn false
if it becomes necessary to use the alternative. Of course this is only if the alternative makes better sense overjavascript:
.
Also, I have yet to see a answer to my question shown (clearly I think) in the first paragraph.Thanks, david. :)I have seen
href="javascript:void(0)"
and I have seenhref="javascript:;"
Is there any reason I would not just usehref="javascript:"
instead?
解决方案Doesn't answer you question but may shed a bit more light on it, some early versions of browsers like netscape had problems when a script was used within the
href
.The
void
operator was pretty much to only way force the click to do nothing.Now, with browsers properly implementing "pseudo URLs", you can safely just use
javascript:;
.这篇关于为什么使用`javascript:void(0)`而不是`javascript:`作为href做什么占位符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!