我正在尝试实现幻灯片放映,我编写了以下代码,但它无法正常工作很可能是因为此行$('#contain').children();
返回[object Object]
而不是我可以迭代的 DOM 元素?
Complete code:
function startSlideShow(interval) {
//var slides = $('#contain').children();
var slides = $('#contain').children().get();
console.log("0: " + slides);
slides.each(function () {
console.log($(this));
});
for (var i = 0; i < slides.length; i++) {
setTimeout(
function () {
var slide = $(slides[i]).children();
console.log("1: " + slide);
$('#currentImage').attr('src', slide[0].src).fadeIn(interval * 100);
$('#slideDesc').html(slide[1].innerHTML).fadeIn(interval * 100);
}, interval * 1000);
}
}
in the html:
<article id="imageShow">
<div class="image">
<img src="" id="currentImage" />
</div>
<div id="imageCover"></div>
</article>
<article id="contain">
<div class="image">
<img src="http://i.imgur.com/925p6M5.jpg" />
<span>1Lorem Ipsum is simply dummy text of the printing and typesetting industry. </span>
</div>
<div class="image">
<img src="http://i.imgur.com/dbBu5rk.jpg" />
<span>2 Lorem Ipsum is simply dummy text of the printing and typesetting industry. </span>
</div>
<div class="image">
<img src="http://i.imgur.com/VFxPGEi.gif" />
<span>3 Lorem Ipsum is simply dummy text of the printing and typesetting industry. </span>
</div>
</article>
在控制台中我收到如下错误:'Uncaught TypeError: Cannot read property 'src' of undefined'