gpt4 book ai didi

javascript - 如何在每个复选框后获得四个以下文本输入?

转载 作者:行者123 更新时间:2023-11-30 07:46:44 26 4
gpt4 key购买 nike

我像这样遍历复选框:

$('.day').each(function() {
// here I need to get the following 4 text inputs in the HTML
// and set some attributes on them
});

在每个复选框之后有四个文本输入字段(周围还有一些 div、CSS 的 span 标签)。所以在上面的循环中,我需要在 HTML 源代码中获取复选框后面的四个文本输入字段,以便我可以在它们上设置一些属性。

我该怎么做?

最佳答案

没有标记很难说,但你可以试试这个。

$('.day').each(function() {
$(this).nextAll('input').slice(0,4).attr('someAttribute','somevalue');
});

如果有一些停止点,比如另一个 .day元素,你可以使用 nextUntil然后.filter() .

$('.day').each(function() {
$(this).nextUntil('.day').filter('input').attr('someAttribute','somevalue');
});

编辑:当你说有一些<div>以及围绕它们的其他标记,我假设您的意思是在它们之间

如果您实际上是说输入嵌套在其中,那么您可以这样做:

$('.day').each(function() {
$(this).nextAll(':has(input)').slice(0,4).find('input').attr('someAttribute','somevalue');
});

或者可能是这样的:

$('.day').each(function() {
$(this).nextAll().find('input').slice(0,4).attr('someAttribute','somevalue');
});

或者,如果有一个停止点,你可以像另一个一样指示 .day , 使用 nextUntil() :

$('.day').each(function() {
$(this).nextUntil('.day').find('input').attr('someAttribute','somevalue');
});

关于javascript - 如何在每个复选框后获得四个以下文本输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4681022/

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