![]() |
#2
暗夜流萤2016-09-16 13:18
回复 楼主 xxmmxmxm
|
index.html:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>档</title>
</head>
<body>
<script src="/1.js"></script>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>档</title>
</head>
<body>
<script src="/1.js"></script>
</body>
</html>
案例一:
1.js:
document.write("<script src=\"/2.js\"></script>");
alert('1'););
alert('1'););
2.js:
alert('2');
、弹出:2和1 ;运行index.html时先弹出2,再弹出1,说明在执行到1.js的alert('1');之前先执行了2.js里的代码案例二:
1.js:
document.write("<script src=\"/2.js\"></script>");
console.log(1);
2.js: console.log(1);
console.log(2);
、输出:1和2 ;把alert函数改成了console.log(),这时输出的顺序分别是1和2,搞不懂了案例三:
1.js:
document.write("<script src=\"/2.js\"></script>");
console.log(t);
2.js: console.log(t);
function t(){}
、输出: t is not defined ;在2.js中定义一个t函数,该函数t在1.js中没有定义,为什么、这是在工作中遇到的,自认为有点难度,谁帮我解决下