js动态切换图片

时间:2024-04-28 11:37:48
<script language =javascript >
$(function () {
initAds(); });
function initAds() {
var curIndex = 0;
var timeInterval = 2500;
var arr = new Array();
arr[0] = "../../Resource/img/lizi/ad-img1.png";
arr[1] = "../../Resource/img/lizi/ad-img2.png";
arr[2] = "../../Resource/img/lizi/ad-img3.png";
setInterval(changeImg, timeInterval);
function changeImg() {
var obj11 = document.getElementById("obj");
if (curIndex == arr.length - 1) {
curIndex = 0;
}
else {
curIndex += 1;
}
obj11.src = arr[curIndex];
}
} </script>