$=function(obj){return document.getElementsByClassName(obj)[0];}
//图片地址
var imgsrc= new Array();
imgsrc[0]="http://img1.gtimg.com/0/68/6884/688412_550x550_0.jpg";
imgsrc[1]="http://img1.gtimg.com/0/68/6899/689943_550x550_0.jpg";
imgsrc[2]="http://img1.gtimg.com/0/68/6899/689941_550x550_0.jpg";
imgsrc[3]="http://img1.gtimg.com/0/68/6884/688414_550x550_0.jpg";
imgsrc[4]="http://img02.taobaocdn.com/tps/i2/T1z5BEXjJvXXXXXXXX-638-369.jpg";
imgsrc[5]="http://img05.taobaocdn.com/tps/i5/T1Vx4EXeleXXXXXXXX-638-369.jpg";
imgsrc[6]="http://img02.taobaocdn.com/tps/i2/T12zVEXk4bXXXXXXXX-638-369.jpg";
imgsrc[7]="http://img07.taobaocdn.com/tps/i7/T15wlEXmlEXXXXXXXX-638-369.jpg";
imgsrc[8]="http://img01.taobaocdn.com/tps/i1/T1tjxEXclXXXXXXXXX-638-369.jpg";
//图片预加载
var arr = new Array();
for(var i=1; i<=imgsrc.length; i++) {
arr[i] = new Image();
arr[i].src=imgsrc[i];
arr[i].onload;
}
i=0;
$("next").onclick=function (){
i++;
if(i>=imgsrc.length){i=0}
$("showimg").setAttribute("src",imgsrc[i]);
}
$("pre").onclick=function (){
i--;
if(i<0){i=imgsrc.length-1}
$("showimg").setAttribute("src",imgsrc[i]);
}
如何让这一块代码在同一个页面多次使用?
通过别的方法已解决