国产探花免费观看_亚洲丰满少妇自慰呻吟_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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 雅安市| 黎川县| 宕昌县| 林州市| 冀州市| 锡林郭勒盟| 石阡县| 旬邑县| 云安县| 柳河县| 惠来县| 大港区| 桂平市| 明星| 涟水县| 临桂县| 浮梁县| 文昌市| 张家港市| 津南区| 天峻县| 临澧县| 金山区| 隆德县| 武义县| 双牌县| 长武县| 内丘县| 沙河市| 高平市| 镇宁| 阳城县| 镇江市| 延吉市| 百色市| 卫辉市| 恭城| 修武县| 中方县| 九寨沟县| 嵊泗县|