如何禁止运行已经添加的js?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>禁止js</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/javascript">
function ban_js(){
// 怎样使得后面的not_used.js不生效?
// not_used.js代码如: alert("hello world");
}
window.onload = band_js();
</script>
<script type="text/javascript" src="not_used.js"></script>
</head>
<body>
</body>
</html>

解决方案 »

  1.   

    楼主这个好像没有办法,除非你在引用那个js文件的最前方加上return false;
      

  2.   

    not_used.js的执行顺序比window.onload要早。要在window.onload中影响已经发生过的事情,你需要的是时光机器。
      

  3.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <script type="text/javascript">
    alert(document.getElementsByTagName('script').length);
    window.onload = function() {
    alert(document.getElementsByTagName('script').length);
    }
    </script>
    <script type="text/javascript" src="test.js"></script>
    </head>
    <body>
    </body>
    </html>
    lz看下上面这段代码,由于html解释运行是按照从上到下的顺序,所以在test.js执行之前,他只能得到她自己,所以script数量是1,当onload的时候,说明html全部解释完成,但是test.js也已经执行。他得到的虽然是2,但是 也已经没有什么效果了。
    综上,想要在script前面把下面的script禁掉,那是无解的
      

  4.   


    function ban_js(){
            return;
            // 怎样使得后面的not_used.js不生效?
            // not_used.js代码如: alert("hello world");
        }