在计时器之后,图像 div 变为空白,而不是切换到下一张图片。它应该循环图像1-4并无限重复
$('.carouselImageJavascriptActive').removeClass('carouselImageJavascriptActive');
$(this).addClass('carouselImageJavascriptActive');
var imgs=$(this).attr('.carouselImage')
var self = $(this);
var myImage = new Array();
var x=0;
myImage[0]='img/image1.jpg';
myImage[1]='img/image2.jpg';
myImage[2]='img/image3.jpg';
myImage[3]='img/image4.jpg';
setTimeout(function() {
var img = document.getElementById('.carouselImageJavascriptActive');
img.src = myImage[x];
x++;
if(x >= myImage.length){
x = 0;
}
},2000);
HTML
<div id='challengeTwoImageJavascript' class='sectionChallengeCarouselImage'>
<img id='imgj1' imgn='1' class='carouselImage carouselImageJavascriptActive' src='img/image1.jpg'/>
<img id='imgj2' imgn='2' class='carouselImage' src='img/image2.jpg'/>
<img id='imgj3' imgn='3' class='carouselImage' src='img/image3.jpg'/>
<img id='imgj4' imgn='4'class='carouselImage' src='img/image4.jpg'/>
</div>