<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>轮播图</title> <script> var number=1; var img= null; function fun(){ number++; if(number>3){ number=1; } img= document.getElementById("img"); img.src="img/banner_"+number+".jpg"; } setInterval(fun,3000); </script></head><body> <img src="img/banner_1.jpg" id="img" width="100%"></body></html>
来源:https://www.cnblogs.com/newcityboy/p/11403285.html