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>

以上这篇js阻止浏览器默认行为的简单实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持phpstudy。


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3