js阻止浏览器默认行为

 js阻止浏览器默认行为

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <a id="a1" href="http://www.baidu.com">百度</a>
        <script>
            function stopDefault(e){
                //非IE
                if(e && e.preventDefault)
                    e.preventDefault();
                //IE
                else
                    window.event.returnValue = false;
            }
            window.onload = function(e){
                var a1 = document.getElementById("a1");
                a1.onclick = function(e){
                    stopDefault(e);
                }
            };
        </script>
    </body>
</html>

 

posted on 2016-05-14 16:16  cag2050  阅读(397)  评论(0编辑  收藏  举报

导航