国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > JS > 正文

在javascript嵌套時的執行順序問題

2024-09-06 12:40:47
字體:
來源:轉載
供稿:網友

先進行了測試,我們創建下面的測試環境。

 
文件 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='index.js'></scr" + "ipt>");
alert('end');
</script>
</head>

<body>

</body>
</html>

 
被 index.html 嵌入的 index.js
document.write("<scr" + "ipt type='text/javascript' src='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='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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 韩城市| 务川| 奉新县| 壤塘县| 根河市| 方正县| 新宾| 启东市| 嘉义市| 延庆县| 张家港市| 保定市| 茶陵县| 延安市| 普陀区| 环江| 两当县| 博罗县| 玉田县| 长顺县| 文登市| 镇原县| 松江区| 临清市| 巧家县| 河间市| 岳普湖县| 沈丘县| 精河县| 金山区| 永登县| 长寿区| 抚州市| 花莲市| 灌云县| 滨州市| 闽清县| 神农架林区| 蒙阴县| 吕梁市| 丹阳市|