用 class 检查每个 div 的下一个输入

check input next of every div with class

我在加载页面时试图检查所有输入。

我的 html 是:

    <td class="even bundlecheckbox">
    <input onclick="bundle.changeSelection(this)" class="checkbox bundle-option-1 validate-one-required-by-name" id="bundle-option-1-2" type="checkbox" name="bundle_option[1][]" value="2"></td>

它可能重复 10 次或 4 次。

我试着用 jQuery 做成这样:

jQuery(document).ready(function() {
    jQuery('.bundlecheckbox').next('input').prop("checked",true);
});

但我想我错过了什么。

Checkbox 是 child 所以使用 Descendant Selector ("ancestor descendant").

Selects all elements that are descendants of a given ancestor.

使用

jQuery('.bundlecheckbox input:checkbox').prop("checked",true);

,也可以使用.find().children()

jQuery('.bundlecheckbox').find('input:checkbox').prop("checked",true);

input 是 td class 的 children .bundlecheckbox 它不是兄弟姐妹或下一个元素

jQuery('.bundlecheckbox').find("input[type='checkbox']").prop("checked",true);

更改值并禁用

jQuery('.bundlecheckbox').find("input[type='checkbox']").prop("value", "3");
jQuery('.bundlecheckbox').find("input[type='checkbox']").prop("disabled", true)