gpt4 book ai didi

jquery 迭代子元素

转载 作者:行者123 更新时间:2023-12-03 21:32:10 26 4
gpt4 key购买 nike

我有一个 ID 为 ring-previewdiv,它具有未指定数量的 img 元素,其类为 stone -在其中预览

我想迭代每个子图像并调用:

$(this).rotate(ring.stones[i].stone_rotation);

其中 this 指的是 img 元素,i 指的是它在 div 中的位置。

我怎样才能做到这一点?

最佳答案

您正在寻找 .each() method .
例如:

$('.ring-preview').children('img').each(function(i) { 
$(this).rotate(ring.stones[i].stone_rotation);
});

如果<img>元素不是直接子元素,您需要调用 .find而不是.children .

关于jquery 迭代子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4109376/

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