OK,這裏是東西,我寫了一個幻燈片一個簡單的代碼,它的工作原理,它是如我所料,這就是它:是這麼想的工作,一個簡單的JavaScript代碼@ _ @
var slideShowImage = document.getElementById("slideShowImage");
var images = ["_Images/Image_01.jpg","_Images/Image_02.jpg","_Images/Image_03.jpg","_Images/Image_04.jpg","_Images/Image_05.jpg","_Images/Image_06.jpg","_Images/Image_07.jpg"];
var imageIndex = 0;
function changeImage(){
slideShowImage.setAttribute ("src",images[imageIndex]);
imageIndex++;
if (imageIndex >= images.length){
imageIndex = 0;
}
}
setInterval (changeImage,3000);
但是當我還在學習javaScript時,我想改變邏輯來品嚐自己,並且我重寫了代碼,但它不起作用,我不知道爲什麼...... 希望有人能夠啓發我,的...
var imageId = document.getElementById("slideShowImage");
var imageNumber = 1;
var imageName = "_Images/Image_0"+imageNumber+".jpg";
function changeImage(){
imageId.setAttribute("Src",imageName);
imageNumber++;
if (imageNumber==7){
imageNumber=1;
}
}
setInterval(changeImage,1000);
你添加了這個事件嗎?我的意思是把它們包裝在一個函數中,然後在window.onload上註冊它。 – 2013-04-10 09:35:46