Jquery按名称或数据检查所有选择

时间:2018-03-05 18:45:45

标签: jquery checkbox

我有一个像这样的复选框列表:

   <li class="pods-pick"><div class="pods-field pods-boolean">
    <input name="pods_meta_type-a[0]" data-name-clean="pods-meta-type-a" data-label="type a" id="pods-form-ui-pods-meta-type-a0" class="pods-form-ui-field-type-pick" type="checkbox" tabindex="2" value="7505" wtx-context="BCB750E9-52A0-4F42-9733-31C9C7762617">
    <label class="pods-form-ui-label" for="pods-form-ui-pods-meta-type-a0">
        type-a1
    </label>
</div>
</li>
<li class="pods-pick"><div class="pods-field pods-boolean">
    <input name="pods_meta_type-a[0]" data-name-clean="pods-meta-type-a" data-label="type a" id="pods-form-ui-pods-meta-type-a1" class="pods-form-ui-field-type-pick" type="checkbox" tabindex="2" value="7506" wtx-context="BCB750E9-52A0-4F42-9733-31C9C7762617">
    <label class="pods-form-ui-label" for="pods-form-ui-pods-meta-type-a1">
        type-a2
    </label>
</div>
</li>

我不能按类使用选择,因为我在同一个表单上有另一个列表“pods-form-ui-field-type-pick”。

如何通过名称(但它是数组)或数据名称清除来检查所有复选框?

我试过

$('*[data-name-clean="pods-meta-type-a"]').prop('checked', true);

但不起作用。

谢谢。

1 个答案:

答案 0 :(得分:0)

$('*[data-name-clean="pods-meta-type-a"]').prop('checked', true);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
   <li class="pods-pick"><div class="pods-field pods-boolean">
    <input name="pods_meta_type-a[0]" data-name-clean="pods-meta-type-a" data-label="type a" id="pods-form-ui-pods-meta-type-a0" class="pods-form-ui-field-type-pick" type="checkbox" tabindex="2" value="7505" wtx-context="BCB750E9-52A0-4F42-9733-31C9C7762617">
    <label class="pods-form-ui-label" for="pods-form-ui-pods-meta-type-a0">
        type-a1
    </label>
</div>
</li>
<li class="pods-pick"><div class="pods-field pods-boolean">
    <input name="pods_meta_type-a[0]" data-name-clean="pods-meta-type-a" data-label="type a" id="pods-form-ui-pods-meta-type-a1" class="pods-form-ui-field-type-pick" type="checkbox" tabindex="2" value="7506" wtx-context="BCB750E9-52A0-4F42-9733-31C9C7762617">
    <label class="pods-form-ui-label" for="pods-form-ui-pods-meta-type-a1">
        type-a2
    </label>
</div>
</li>