再会!我不确定这段代码有什么问题。它应该每 N 秒更改一次 div 的背景图像并循环遍历数组。提前致谢
window.setInterval(foo(), 400);
//
var arr = [
"img1.jpg",
"img2.jpg",
"img3.jpg"
];
//Set up variables
var waitTime = 5;
var main = document.getElementById("main");
var i = 0;
function foo() {
main.style.backgroundImage = "url(" + arr[i] + ")";
if (i > arr.length) {
i = 0;
} else {
i++;
}
}