本文实例为大家分享了js实现背景自动切换的具体代码,供大家参考,具体内容如下
功能:
窗口打开背景图自动跳转切换
所有代码:
<!DOCTYPE html> <html lang="en"> <head> <Meta charset="UTF-8"> <title>背景切换</title> </head> <body> <img src="img/1.jpg" width="500" id="imgId"/> </body> </html> <script type="text/javascript"> window.onload = function () { setInterval(step,1000); } var num = 1; function step() { if (num < 5) { num++; } else { num = 1; } var dom = document.getElementById("imgId"); //更改它images的src属性 dom.src = 'img/' + num + '.jpg'; } </script>原文链接:https://www.f2er.com/js/526290.html