第一张图片会出现,但其他图片则不会出现。我不认为脚本可以找到它们。如何将其指向我的图像?
JavaScript的:
var myImgage=document.getElementById("slideshow");
var imageArray=["healing.jpg","holiday.jpg","nye.jpg","basketball.jpg"]
var imageIndex=0;
function changeImage () {
slideshow.setAttribute("src", imageArray [imageIndex]);
imageIndex++;
if (imageIndex>=imageArray.length) {
imageIndex=0;
}
}
var intervalHandle = setInterval(changeImage,2000);
slideshow.onclick=function () {
clearInterval(intervalHandle);
}
HTML:
<img id="slideshow" src="image/healing.jpg" width="80%" height="40%"/>
<script src="java/slideshow.js"></script>
答案 0 :(得分:1)
尝试将imageArray更改为以下
var imageArray=["image/healing.jpg","image/holiday.jpg","image/nye.jpg","image/basketball.jpg"]
答案 1 :(得分:0)
将slideshow
变量替换为myImgage
。还可以通过在图像数组中添加image/
来修复图像路径。