案例l
轮播图
用到setInterval(fun,3000);--------属于window对象里面的循环定时器方法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>轮播图</title> </head> <body> <img id="img" src="img/banner_1.jpg" width="100%"> <script> var number = 1; function fun() { number++; if(number>3){ number = 1; } var img = document.getElementById("img"); img.src = "img/banner_"+number+".jpg"; } setInterval(fun,3000); </script> </body> </html>