【发布时间】:2019-10-19 04:20:50
【问题描述】:
程序运行时,屏幕上只显示最后一个数组值图像,其他图像不显示。
这是 HTML 代码
<img id="mg" alt="image not found">
这里是javascript代码
var images=["image", "image2","img","imag"]
test();
function test(){
var index = 0;
for(var count=0; count<images.length; count++){
document.getElementById('mg').src = images[count] + ".jpg";
document.getElementById("mg").width = "500";
document.getElementById("mg").height = "300";
index = index + 1;
setTimeout(test, 1000);
if(index + 1 > images.length){
index = 0;
count = 0;
}
}
}
【问题讨论】:
-
为什么不使用 CSS 来代替呢?这与这个问题/答案非常相似:stackoverflow.com/a/58177780/362536
-
我正在学习在 javascript 中使用它
标签: javascript html css