jQuery:循环遍历两个ID内的所有元素
我试图循环遍历两个 div 内的每个 .required:#A 和 #B。
$('#A .required').nextUntil('#B').each(function() {
console.log($(this).attr("name"));
});
上面似乎只获取了两个 div 中的最后一个元素。我该如何解决这个问题?
I'm trying to loop through each .required within two divs: #A and #B.
$('#A .required').nextUntil('#B').each(function() {
console.log($(this).attr("name"));
});
The above only seems to get the last element within the two divs. How can I fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不太确定我理解这背后的 HTML,但也许您想要:
这会获取所有标记为“required”类的元素,这些元素是 id 为“A”的元素或 id 为“B”的元素的后代。
Not exactly sure I understand the HTML behind this, but maybe you want:
That gets all the elements marked with class "required" that are descendants of either the element with id "A" or the one with id "B".