错误为未捕获的TypeError:无法读取undefined的属性(阅读'style')
编码:
let slideIndex = 0;
showSlides();
function showSlides() {
let i;
let slides = document.getElementsByClassName("mySlides");
let dots = document.getElementsByClassName("dot");
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slideIndex++;
if (slideIndex > slides.length) {slideIndex = 1}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex-1].style.display = "block"; //Error is showed at this line
dots[slideIndex-1].className += " active";
setTimeout(showSlides, 2000); // Change image every 2 seconds
}
我在公共文件夹的index.html中包含了我的script标记。除此之外,其余javascript文件都正常工作。
2条答案
按热度按时间zc0qhyus1#
常量mystyle = {显示:“块”,};
e4yzc0pl2#
常量mystyle = {显示:“块”,};