試圖創建一個類與JavaScript的簡單幻燈片。出於某種原因,圖像未加載到div中。圖像沒有填充div
腳本:
var imageArray = ['img/br1.jpg', 'img/br2.jpg', 'img/br3.png', 'img/br4.gif', 'img/br5.jpeg', 'img/br6.jpeg', 'img/br7.jpeg'];
var i = 0;
function slideShow() {
document.getElementById('slideshowdiv').src = imageArray[i];
//increment i by 1
i++;
// checks if i is greater than or equal to the length
if(i >= imageArray.length) {
// if true, resets value to 0
i = 0;
};
//recall the change function every 2 seconds
timer = setTimeout('slideShow()', 2000);
}
function stopShow() {
clearTimeout(timer);
};
HTML:
<body onload="slideShow()">
<div id="slideshowdiv"></div>
不要使用'setTimeout'也不'setInterval'處理字符串,因爲它就像邪惡'eval'!使用函數:'setTimeout(slideShow,2000)' – Oriol
檢查控制檯是否有錯誤? – j08691
是的,沒有。 @ j08691 – trev