1 <!DOCTYPE html> 2 <html> 3 <head lang="en"> 4 <meta charset="UTF-8"> 5 <title></title> 6 </head> 7 <body> 8 <img id="img" src="gallery-img1.png" alt=""/> 9 </body> 10 </html> 11 <script> 12 var img = document.getElementById("img"); 13 var arr = ["./gallery-img1.png","./gallery-img2.png","./gallery-img3.png"]; 14 15 var i=1; //因为打开就是第一张图片,如果从i=0开始,就延迟1秒 16 17 setInterval(( function s(){ 18 img.src=arr[i]; 19 i++; 20 if(i>arr.length){ 21 i=0; 22 img.src=arr[i]; 23 i++; 24 } 25 }),1000); 26 </script>