我试图让传送带在访问页面后立即启动并每2.5秒循环一系列图像,但不会超过第一张图像。我环顾这里和w3schools,但一直未能找到我的问题所在。任何帮助将不胜感激!图片传送带不会前进(HTML/JavaScript)
的JavaScript如下:
window.onload slideShow();
var i=0;
function slideShow() {
window.setInterval("nextSlide()", 2500);
}
function nextSlide() {
var images["images/stockton0.jpg",
"images/stockton1.jpg"
"images/stockton2.jpg"
"images/stockton3.jpg"
"images/stockton4.jpg"
"images/stockton5.jpg"
"images/stockton6.jpg"
"images/stockton7.jpg"
"images/stockton8.jpg"
"images/stockton9.jpg"
"images/stockton10.jpg"]
var photo = document.getElementByClass("stocktonPics");
photo.src = images[i];
i++;
}
HTML代码:
<img class="stocktonPics" src="images/stockton0.jpg" alt="slides">
所以1 - 其[getElementsByClassName方法]( https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName),它返回一个数组。这意味着它应该是'photo [0] .src。 2 - 你应该检查你的控制台是否有错误,这将会指向你正确的方向 – Craicerjack