js为链接绑定点击事件并且附带return false;来阻止跳转

<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="gb2312" />
        <title></title>
        <style>
         
        </style>
    </head>
    <body>
        <a href="http://www.baidu.com" target="_blank">百度跳转</a>
        <a href="http://www.baidu.com" target="_blank" id="test">阻止默认事件</a>
        <script>
            document.getElementById('test').onclick = function(e){
                e = e || window.event;
                if (e.preventDefault) {
                    e.preventDefault();
                } else {
                    e.returnValue = false;
                }
            }
        </script>
    </body>
</html>            

  

posted @ 2014-09-29 16:20  唸随爱  阅读(382)  评论(0编辑  收藏  举报