gpt4 book ai didi

javascript - JQuery 根据 tr 的类名检查 td 中的所有复选框

转载 作者:行者123 更新时间:2023-11-28 19:51:35 24 4
gpt4 key购买 nike

这是我的示例代码

<table id="accessListTable">
<tr class="ui-grid groupHead">
<td><input type="checkbox" class="groupHeadCheck"/></td>
</tr>
<tr>
<td><input type="checkbox" id="1"/></td>
</tr>
<tr>
<td><input type="checkbox" id="2"/></td>
</tr>
<tr>
<td><input type="checkbox" id="3"/></td>
</tr>
<tr class="ui-grid groupHead">
<td><input type="checkbox" class="groupHeadCheck"/></td>
</tr>
<tr>
<td><input type="checkbox" id="4"/></td>
</tr>
</table>
  1. 例如,当第一行的复选框带有groupHeadCheck类时,id的所有checkboxex 123 也会被检查。
  2. 如果 1、2、3 的复选框均已选中,则将选中第一行的复选框。

请帮忙!

最佳答案

您可以向组复选框添加一个点击处理程序,然后在处理程序内您可以找到其 tr 元素和 tr 的下一个同级元素,直到下一次出现 tr.groupHead

$(function ($) {
$(".groupHeadCheck").on("click", function (event) {
$(this).closest('tr').nextUntil('tr.groupHead').find('input[type="checkbox"]').prop('checked', this.checked)
})
});

演示:Fiddle

关于javascript - JQuery 根据 tr 的类名检查 td 中的所有复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23365215/

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