网页中的图像均会被自动看作图像对象,并依顺序,分别表示为document.images[0],document.images[1]...

格式:

图像对象名称=new Image([宽度],[高度])   //px

border complete height hspace lowsrc name src vspace width

onAbort onError onKeyDown onKeyPress onKeyUop onLoad

例1:(预载)
<Script>

img0 = new Image();
img0.src = "images/snow0.gif";

img1 = new Image();
img1.src = "images/snow1.gif";

document.write ("已经读取两个图文件,但此时不显示。");

</Script>

例2:
<Script>
function img-preload(idx){
    eval("img"+idx+" = new Image()");
    eval("img"+idx+".src = 'images/snow"+idx+".gif'");
}

img-preload(0);
img-preload(1);
document.write ("已经读取两个图文件,但此时不显示。");

</Script>

例3:
<Script>
function img-preload(imgname,idx){
    eval("img"+idx+" = new Image()");
    eval("img"+idx+".src = 'images/"+imgname+".gif'");
}

img-preload("snow0",0);
img-preload("snow1",1);
document.write ("已经读取两个图文件,但此时不显示。");

</Script>

 

Copyright © 2009-2010 HTML5中文网 版权所有