gpt4 book ai didi

jquery - 如何使用 jQuery 遍历 div 的子元素?

转载 作者:IT王子 更新时间:2023-10-29 03:23:46 24 4
gpt4 key购买 nike

我有一个 div,其中有几个输入元素...我想遍历每个元素。想法?

最佳答案

使用children()each() ,您可以选择将选择器传递给 children

$('#mydiv').children('input').each(function () {
alert(this.value); // "this" is the current element in the loop
});

您也可以只使用直接子选择器:

$('#mydiv > input').each(function () { /* ... */ });

关于jquery - 如何使用 jQuery 遍历 div 的子元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3024391/

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