<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>无标题文档</title> <script type="text/javascript"> var newload= function(){ urlone="http://www.leyoo.com/Public/nImg/Zhuanti/20131231/run_img_" urllast=".png" for(var i=1; i<9; i++) { url = urlone + i + urllast; oid = "im"+i; imgLoad(url,fimg); } } var fimg=function(x,y){ document.getElementById(oid).width = x; document.getElementById(oid).height = y; document.getElementById(oid).src = url; } var imgLoad = function (url, callback) { var img = new Image(); img.src = url; if (img.complete) { callback(img.width, img.height); } else { img.onload = function () { callback(img.width, img.height); img.onload = null; }; }; }; </script> </head> <body> <a onClick="newload()">点击</a> <img src="myFocus_white.gif" id="im1" /> <img src="myFocus_white.gif" id="im2"/> <img src="myFocus_white.gif" id="im3"/> <img src="myFocus_white.gif" id="im4"/> <img src="myFocus_white.gif" id="im5"/> <img src="myFocus_white.gif" id="im6"/> <img src="myFocus_white.gif" id="im7"/> <img src="myFocus_white.gif" id="im8"/> </body> </html>
小练习一下