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

问题描述 投票:0回答:1

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

   <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);

但不起作用。

谢谢。

jquery checkbox
1个回答
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>
© www.soinside.com 2019 - 2024. All rights reserved.