【发布时间】:2019-05-22 20:41:41
【问题描述】:
我在第 12 行收到“Uncaught TypeError: Cannot read property 'style' of undefined”我不知道为什么
class Slider {
duration = 0;
currentSlide = 0;
slides = document.getElementsByClassName("slide");
constructor() {
this.initSlide();
}
initSlide() {
var i;
for (i = 0; i < this.slides.length; i++) {
this.currentSlide[i].style.display = "none";
}
this.currentSlide++;
if (this.currentSlide > this.slides.length) {
this.currentSlide = 1
}
this.slides[this.currentSlide - 1].style.display = "block";
setTimeout(this.initSlide, 3000);
}
}
【问题讨论】:
标签: javascript