默认事件~

默认事件的阻止

  简单的默认事件阻止
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <a onclick="fn(event)" href="http://www.baidu.com">123</a>
        <script>
            //js和html是两门不同的语言,分开运行
            function fn(e){
                var e=e||window.event;
                if(e.preventDefault){
                    e.preventDefault();
                }else{
                    e.returnValue=false;//ie阻止默认事件
                }
                console.log(e);
            }
        </script>
    </body>
</html>

 

posted @ 2019-07-11 19:27  深夜的海洋  阅读(143)  评论(0编辑  收藏  举报