Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jQuery';s.each()函数将函数附加到多个幻灯片容器_Jquery_Function_Cycle_Each - Fatal编程技术网

使用jQuery';s.each()函数将函数附加到多个幻灯片容器

使用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" />

我有很多小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" />
        <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')
    });
});