checkbox全选

发布时间 2023-07-27 21:39:23作者: .net&new


<input type="checkbox" id="ckall" onclick="checkall()"/>全选
<input type="checkbox" class="ckitem" />学习
<input type="checkbox" class="ckitem" />吃饭
<input type="checkbox" class="ckitem" />打游戏
<input type="checkbox" class="ckitem" />运动


function checkall(){
// 判断全选按钮是否被选中checked
if($("#ckall").is(":checked") == true){
$(".ckitem").each(function(){
$(this).prop("checked",true); // 通过prop()函数设置复选框的选中状态
})
}
else{
$(".ckitem").each(function(){//each是循环遍历
$(this).prop("checked",false);
})
}
}

原文链接:https://blog.csdn.net/weixin_45947938/article/details/124738353