如何使用jQuery遍历div的子元素? [英] How do I iterate through children elements of a div using jQuery?
本文介绍了如何使用jQuery遍历div的子元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个div,其中有几个输入元素...我想遍历每个元素。
I have a div and it has several input elements in it... I'd like to iterate through each of those elements. Ideas?
推荐答案
使用 children()
和 each()
,您可以选择将选择器传递给孩子
$('#mydiv').children('input').each(function () {
alert(this.value); // "this" is the current element in the loop
});
您还可以使用直接子选择器:
You could also just use the immediate child selector:
$('#mydiv > input').each(function () { /* ... */ });
这篇关于如何使用jQuery遍历div的子元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文