这是我幻灯片的HTML代码
<img src="images/1.jpg" id="image" style="width:230px; border-bottom:2px solid #000">
<br>
<input type="button" value="Start Slide Show" onClick="startSlideShow()">
<input type="button" value="Stop Slide Show" onClick="stopSlideShow()">
这是我的Javascript的代码,但if条件在这里不起作用。你能解决这个问题吗?
<script>
var intervalID;
function startSlideShow(){
intervalID = setInterval(changeImage, 800);
}
function stopSlideShow(){
clearInterval(intervalID);
}
function changeImage(){
var imageSrc = document.getElementById("image").getAttribute("src");
var currentImageNumber = imageSrc.substring(imageSrc.lastIndexOf("/") + 1, imageSrc.lastIndexOf("/") + 2);
if(currentImageNumber == 7){
currentImageNumber == 0;
}
document.getElementById("result").innerHTML = currentImageNumber;
document.getElementById("image").setAttribute("src", "images/" + (Number(currentImageNumber)+1) + ".jpg");
}
changeImage();
</script>
答案 0 :(得分:0)
我认为代码中的部分是
currentImageNumber == 0
应该是
currentImageNumber = 0
以循环播放图像