gpt4 book ai didi

javascript - 循环遍历每个容器中的所有元素

转载 作者:行者123 更新时间:2023-11-28 19:32:35 25 4
gpt4 key购买 nike

我需要循环遍历每个容器中的所有项目,每次循环到达新容器时都从 1 开始。

编辑:添加了 JSFiddle http://jsfiddle.net/ntv4k4LL/

例如

Container

- 1
- 2
- 3

Container

- 1
- 2
- 3

但目前正在发生

Container

- 1
- 2
- 3

Container

- 4
- 5
- 6

这是我的代码:

$('.index-slide-rel').each(function(){

$(this).children('article').each(function(i,e){

col++;

if(i > 0 && i%cols === cols-1) {
sx= 0;
row++;
col=1;
sy += previewElementHeight;
}
})
});

最佳答案

$('.index-slide-rel').each(function(i, container) {
// here, i should take the value 0 to 1, considering you have 2 containers.
$(container).children('article').each(function(j, element) {
// here, j should take the value 0 to 2, considering you have 3 elements.
});
});

关于javascript - 循环遍历每个容器中的所有元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26476997/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com