<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>每天一个JavaScript实例-推断图片是否载入完毕</title> <script> window.onload= function(){ //clearTimeout(clock); alert("载入完毕"); } var item = document.getElementsByTagName("img"); var clock = setTimeout(function(){ //var item = document.getElementsByTagName("img"); //console.log(item); //console.log(item.item(item.length-1).onload); if(item.item(item.length-1).onload == null){ alert("还没载入完毕呢!");} },1000) </script> </head> <body> <img src="http://i1.hoopchina.com.cn/blogfile/201401/13/BbsImg138957793449615_500*311.jpg" /> <img src="http://www.xyzwallpaper.com/wp-content/uploads/2014/07/girl-wallpaper-300x300.jpg" /> <img src="http://www.xyzwallpaper.com/wp-content/uploads/2014/07/girl-wallpaper-2-300x300.jpg" /> <img src="http://www.xyzwallpaper.com/wp-content/uploads/2014/07/girl-wallpaper-3-300x300.jpg" /> <img src="http://www.xyzwallpaper.com/wp-content/uploads/2014/07/girl-wallpaper-4-300x300.jpg" /> <img src="http://bestpaperz.com/data_images/out/40/8903786-shakira-in-the-chair.jpg" /> <img src="http://bestpaperz.com/data_images/out/40/8903770-red-currant.jpg" /> <img src="http://i1.hoopchina.com.cn/blogfile/201401/13/BbsImg138957793449615_500*311.jpg" /> <img src="http://bestpaperz.com/data_images/out/40/8903733-failed-surfing.jpg" /> <img src="http://bestpaperz.com/data_images/out/40/8903738-robert-pattinson.jpg" /> <img src="http://i1.hoopchina.com.cn/blogfile/201401/13/BbsImg138957793449615_500*311.jpg" /> <img src="http://bestpaperz.com/data_images/out/40/8903728-empty-bench.jpg" /> <img src="http://i1.hoopchina.com.cn/blogfile/201401/13/BbsImg138957793449615_500*311.jpg" /> <img src="http://bestpaperz.com/data_images/out/40/8903801-snow-park.jpg" /> </body> </html>