清淡凉白开
2016-08-02 17:48
<<!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>
</head>
<body>
<div id="showMsg"></div>
<div>
<img src="images/Hydrangeas.jpg">
<img src="images/Jellyfish.jpg">
<img src="images/Koala.jpg">
<img src="images/Lighthouse.jpg">
</div>
<script type="text/javascript">
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+="domReady比onload快:"+ (time2-time1)+"ms<br>";
}
</script>
</body>
</html>
老师上节课讲的那个domReady的函数你没有引入进HTML页面上,都访问不到domReady函数,当然也就没有结果啦。亦或者你自己在现有的HTML页面中把domReady函数放进去也一样可以。
<script src="myReady.js"></script>
把它反正在head里
没有把myReady脚本引进了
DOM探索之基础详解篇
98374 学习 · 238 问题
相似问题