jQuery遍历子元素 [英] jquery iterate over child elements
本文介绍了jQuery遍历子元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个ID为ring-preview
的div
,其中有未指定数量的img
元素,其中包含类stone-preview
.
I have a div
with the id ring-preview
, it has a unspecifed number of img
elements with the class stone-preview
inside it.
我想遍历每个子图像并调用:
I would like to iterate over each of these child images and call:
$(this).rotate(ring.stones[i].stone_rotation);
其中this
表示img
元素,而i
表示其在div
中的位置.
Where this
refers the img
element and i
refers to its position within the div
.
我该怎么做?
推荐答案
您正在寻找 .each()
方法 .
例如:
You're looking for the .each()
method.
For example:
$('.ring-preview').children('img').each(function(i) {
$(this).rotate(ring.stones[i].stone_rotation);
});
如果<img>
元素不是直接子元素,则需要调用.find
而不是.children
.
If the <img>
elements aren't direct children, you'll need to call .find
instead of .children
.
这篇关于jQuery遍历子元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文