javascript:; 和javascript:void(0);

javascript:; 和javascript:void(0);

1、“javascript:void(0);”要去执行一次表达式“0”,然后返回undefined。


2、“javascript:;”直接返回undefined。

3、例如:

  • 
    <a onclick="fn()">Does not appear as a link, because there's no href</a>
    <a href="javascript:void(0)" onclick="fn()">fn is called</a>
    <a href="javascript:undefined" onclick="fn()">fn is called</a>
    <a href="javascript:" onclick="fn()">fn is called too!</a>
    
    				
  • 
    
    

    上面三个都是等价的

    标签: