使用jQuery';s.each()函数将函数附加到多个幻灯片容器
我有很多小jQuery循环幻灯片div(容器)在一个页面的网站上,比如使用jQuery';s.each()函数将函数附加到多个幻灯片容器,jquery,function,cycle,each,Jquery,Function,Cycle,Each,我有很多小jQuery循环幻灯片div(容器)在一个页面的网站上,比如 <div class="foo bar" data-value="1000"> // data-value varies on each container <img src="directory/img_0.jpg" alt="img 0" /> <img src="directory/img_1.jpg" alt="img 1" />
<div class="foo bar" data-value="1000"> // data-value varies on each container
<img src="directory/img_0.jpg" alt="img 0" />
<img src="directory/img_1.jpg" alt="img 1" />
<img src="directory/img_2.jpg" alt="img 2" />
</div>
对于此类幻灯片div的所有出现。如何将此类jQuery函数“附加”或“绑定”或“链接”到每个幻灯片div,以便使用每个元素的不同数据值?我怀疑jQuery的.each()函数可以允许我这样做,但如何实现呢
编辑
提前非常感谢 正如您所提到的,
.each()
可以让您非常轻松地完成此操作:
$('.foo.bar').each(function() {
$(this).cycle({
speed: 300,
timeout: 6000,
delay: $(this).data('value')
});
});
在
中。每个回调中,这个指的是您当前正在操作的元素。非常感谢您-它按预期工作,我不知道它这么简单;为我回到jQuery幼儿园,为你投赞成票;)
$('.foo.bar').each(function() {
$(this).cycle({
speed: 300,
timeout: 6000,
delay: $(this).data('value')
});
});