我把js放到头文件里怎么就不运行了呢?
放在头文件一点用都没有,移动到body里就正常了,为什么呢?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>domready</title>
<script src="../domReady.js"></script>
<script>
var d = document;
var msgBox = d.getElementById("showMsg");
var imgs = d.getElementsByTagName("img");
var time1 = null, time2 = null;
myReady(function(){
msgBox.innerHTML += "dom已加载!<br>";
time1 = new Date().getTime();
msgBox.innerHTML +="时间截:" + time1 + "<br>";
});
window.onload = function(){
msgBox.innerHTML += "onload已加载!<br>";
time2 = new Date().getTime();
msgBox.innerHTML += "时间戳:" + time2 + "<br>";
msgBox.innerHTML += "时间截:" + (time2 - time1) + "ms<br>";
}
</script>
</head>
<body>
<div id="showMsg"></div>
<div>
<img src="1.jpg"/>
<img src="2.jpg"/>
<img src="3.jpg"/>
<img src="4.jpg"/>
<img src="5.jpg"/>
<img src="6.jpg"/>
</div>
</body>
</html>