js在html中的加载执行顺序
1.加载顺序:引入标记
这样IE下和其他浏览器输出值的顺序都是一直的了:1、2、我是1、3
总结:IE下,用Document.Write方法引用js文件时,js文件会出现尚未加载就直接调用的情况,因此建议将引用的JS文件单独放在一个script块中。以确保引用的js文件完全加载后,再继续执行后面的Document.Write内容
5、同名JS函数执行顺序
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<html>
<head>
<script type= "text/javascript" >
function aa() {
alert('First aa')
}
</script>
<title></title>
</head>
<body>
<form id= "form1" runat= "server" >
<br />
<input id= "Button1" type= "button" value= "button" onclick= "aa();" />
</form>
</body>
<script type= "text/javascript" >
function aa(s) {
alert('Second aa');
}
function aa(s) {
alert('Last aa');
}
</script>
</html>
|
登录后复制
点击“botton”执行结果: Last aa
在js里出现同名函数后,你在web页面里调用改js函数后,总是调用页面中最后一个加载的函数。
以上是详解js在html中的加载执行顺序 的详细内容。更多信息请关注PHP中文网其他相关文章!