我是学习javascript和编程的新手。我从学习网站上复制了这个片段。加班我加载页面我在调试器中得到myImage为空的错误?有人可以帮忙解释一下吗?
谢谢!
var myImage = document.getElementById("mainImage");
var imageArray = ["_images/heretic.jpg","_images/prudential.jpg","_images/woofs_logo.jpg"
];
var imageIndex = 0;
function changeImage() {
myImage.setAttribute( "src",imageArray[imageIndex]);
imageIndex++;
if (imageIndex >= imageArray.length) {
imageIndex = 0;
}
}
// setInterval is also in milliseconds
setInterval(changeImage,5000);
答案 0 :(得分:-1)
也许你没有id =" mainImage" ?