好的,事情就是这样,我为幻灯片编写了一个简单的代码,它可以正常工作,并且正如我所期望的那样,就是这样:
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);