如何使用 jQuery 遍历 div 的子元素? [英] How do I iterate through children elements of a div using jQuery?

查看:16
本文介绍了如何使用 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(),你可以选择通过children

$('#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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆