Layui中复选框checkbox的全选、反选、取消选择示例
HTML代码:
//全选
$(document).on("click","#selall",function(){
$("input:checkbox[name='ditems']").each(function(i){
$(this).prop("checked",true);
})
form.render();
})
//取消选择
$(document).on("click","#canall",function(){
$("input:checkbox[name='ditems']").each(function(i){
$(this).prop("checked",false);
})
form.render();
})
//反选
$(document).on("click","#selother",function(){
$("input:checkbox[name='ditems']").each(function(i){
if($(this).prop("checked")||$(this).attr("checked")==="checked"){
$(this).prop("checked",!$(this).prop("checked"));
}
else{
$(this).prop("checked",true);
}
})
form.render();
})