如何禁止运行已经添加的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>
<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>
<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禁掉,那是无解的
function ban_js(){
return;
// 怎样使得后面的not_used.js不生效?
// not_used.js代码如: alert("hello world");
}