如果你想要一个事件或一个空的javascript调用的链接,有几种方法,我可以想到:
<a href="#">Method 1</a> <- Ugh... changes URL in browser
<a href="javascript:;">Method 1</a> <- My currently preferred method
<a href="javascript:void(0);">Method 1</a> <- Another approach?
Run Code Online (Sandbox Code Playgroud)
在跨浏览器兼容性和简洁性方面,最好的方法是什么?
如果他们不这样做,请不要使用链接......好吧,链接到任何东西.
相反,使用span有点像这样:
<span class="spanlink" onclick=something>This is some text</span>
Run Code Online (Sandbox Code Playgroud)
在你的CSS中:
.spanlink {
text-decoration: underline;
color: blue;
cursor: pointer; /* Ragnagord's suggestion in comments */
}
Run Code Online (Sandbox Code Playgroud)
Jquery 解决方案..
$('a.preventDefault').click(function(){
return false
});
<a href="#" class="preventDefault">Method 1</a>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8040 次 |
| 最近记录: |