gpt4 book ai didi

jquery - 选中/取消选中表格中的所有复选框

转载 作者:行者123 更新时间:2023-12-01 06:34:09 27 4
gpt4 key购买 nike

我有一个带有复选框列的表格,我添加了以下内容:

<th>
<input type="checkbox" id="selectAll">
</th>

这是我的 jQuery 函数:

jQuery(document).ready(function() {
jQuery('#selectAll').click(function(){
jQuery("input[type='checkbox']").attr('checked', jQuery('#selectAll').is(':checked')); })
});

第一次检查时工作正常,但当我取消选中并尝试再次检查时,它不起作用!有什么原因让它不起作用吗?谢谢

最佳答案

尝试使用.prop()this.checked:

jQuery(document).ready(function() {
jQuery('#selectAll').click(function(){
jQuery("input[type='checkbox']").prop('checked', this.checked);
})
});

关于jquery - 选中/取消选中表格中的所有复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23469634/

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