The content of this article is about the replacement of background images in HTML. It has a certain reference value. Now I share it with you. Friends in need can refer to it.
<p class="p"> <p class="p2"><img src="../img/hu.jpg" alt="" id="picture"></p> </p> </p> var curIndex = 0; var timeInterval = 3000; //切换时间 3秒 可以修改 var arr = new Array(); arr[0] = "../img/hu.jpg"; //这里的是图片存放的相对路径 arr[1] = "../img/bb.jpg"; arr[2] = "../img/cc.jpg"; setInterval(changeImg, timeInterval); function changeImg() { var obj = document.getElementById("picture"); if(curIndex == arr.length - 1) { curIndex = 0; } else { curIndex += 1; } obj.src = arr[curIndex]; }
Related Recommended:
HTML to beautify the uploaded file style
How to use HTML to implement the scrolling barrage function
HTML Implement the ticket grabbing function (set a time to open the ticket grabbing page)
The above is the detailed content of HTML implements background image replacement. For more information, please follow other related articles on the PHP Chinese website!