[导读]先进行了测试,我们创建下面的测试环境。 文件 index.html 用于显示的页面 <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN http://www.w3.org/TR/html4/loose.dtd ><html><head>&...

先进行了测试,我们创建下面的测试环境。   文件 index.html 用于显示的页面

<!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=gb2312">
<title>测试</title>
<script language="javascript">
alert('start');
document.write("<scr" + "ipt type='text/javascript' src='http://www.t086.com/article/index.js'></scr" + "ipt>");
alert('end');
</script>
</head>

<body>

</body>
</html>

  被 index.html 嵌入的 index.js document.write("<scr" + "ipt type='text/javascript' src='http://www.t086.com/article/index1.js'></scr" + "ipt>");
alert('index.js');   被 index.js 嵌入的 index1.js alert('index1.js');   最终的显示提示的顺序: start end index.js index1.js   小结,在存在js嵌套的过程中,首先执行原先的代码,被嵌套的js中再执行。然后是下层嵌套代码的执行。   但是以上的部分只是限于了显示一个提示,如果需要证明这个推论是正确的,我想还是需要通过一些更多的代码来测试的。   我们只是修改index.js index1.js   index.js var str = 'index.js';
document.write("<scr" + "ipt type='text/javascript' src='http://www.t086.com/article/index1.js'></scr" + "ipt>");
alert('index.js');
alert(str);   index1.js alert(str);
str = 'index1.js';
alert('index1.js');
alert(str);   再次运行,顺序: start end index.js index.js index.js index1.js index1.js   显然结果证明了我们上面的推论。   原文地址:http://blog.sina.com.cn/s/blog_47243df301000231.html