1 <script language =javascript > 2 var curIndex=0; 3 //时间间隔 单位毫秒 4 var timeInterval=5000; 5 var arr=new Array(); 6 arr[0]="1.jpg"; 7 arr[1]="2.jpg"; 8 arr[2]="3.jpg"; 9 arr[3]="4.jpg";13 setInterval(changeImg,timeInterval); 14 function changeImg() 15 { 16 var obj=document.getElementById("xuanchuanPic"); 17 if (curIndex==arr.length-1) 18 { 19 curIndex=0; 20 } 21 else 22 { 23 curIndex+=1; 24 } 25 obj.src="images/"+arr[curIndex]; 26 } 27 </script> 28 <img src="image/1.jpg"id="xuanchuanPic" />
时间: 2024-10-14 06:33:16