Ric*_*ani 3 html javascript events
我最近被javascript:void(null); 应用于图像时,我的href中的错误.
在我的Safari版本(Leopard PPC中的4.0.3)中,我应用了javascript的href:void(null); 在图像周围,图像完全从布局中消失.环顾四周我看到这也发生在IE中,虽然我无法确认.
我已经阅读了使用带有onclick处理程序的井号(#)
onclick="return false;"
Run Code Online (Sandbox Code Playgroud)
这有效,但我讨厌将英镑附加到网址上.
我知道有各种各样的技术,那么你如何处理你的hrefs?
像这样
<a href="#" onclick="doSomething(); return false;">
Run Code Online (Sandbox Code Playgroud)
或者最好
<a href="nonJavascriptAlternative.html" id="foo">
Run Code Online (Sandbox Code Playgroud)
然后使用javascript附加一个处理程序 - 在jQuery中
$('foo').click(function() { doSomething(); return false; });
Run Code Online (Sandbox Code Playgroud)
我的首选是
<a href="non_javascript_alternative.html" onclick="doSomething(); return false;">
Run Code Online (Sandbox Code Playgroud)
......在可能的情况下(并非总是如此).在文档加载后,在属性中使用事件处理程序具有以下优点: