event.preventDefault()方法是用于取消事件的默认行为,例如,当点击提交按钮时阻止对表单的提交。但此方法并不被ie支持,在ie下需要用window.event.returnValue = false; 来实现。
注意
1、如果 Event 对象的 cancelable 属性是 fasle,那么就没有默认动作,或者不能阻止默认动作。无论哪种情况,调用该方法都没有作用。
2、此方法并不被ie支持,在ie下需要用window.event.returnValue = false; 来实现。
 
 <script type="text/javascript">
<script type="text/javascript">
var test = document.getElementByIdx_x(‘test‘); 
 
 
 test.onclick =function(e) {
test.onclick =function(e) { 
 
 
 alert(‘URL:‘+this.href +‘, 不会跳转‘);
   alert(‘URL:‘+this.href +‘, 不会跳转‘); 
 
 
 stopDefault(e);
   stopDefault(e); 
 }
 } 
 function stopDefault(e) {
function stopDefault(e) { 
 
 
 if (e && e.preventDefault) {//如果是FF下执行这个
     if (e && e.preventDefault) {//如果是FF下执行这个
 
 
 e.preventDefault();
        e.preventDefault();
 
 
 }else{
    }else{ 
 
 
 window.event.returnValue =false;//如果是IE下执行这个
        window.event.returnValue =false;//如果是IE下执行这个
 
 
 }
    }
 
 
 returnfalse;
    returnfalse;
 }
 }
 </script>
 </script>
 <a href="url" id="test">测试</a>
<a href="url" id="test">测试</a> 原文:http://www.cnblogs.com/stevenjson/p/3549052.html