layui中多选框 默认全选
时间: 2023-11-16 22:07:38 浏览: 103
多选框默认全选的代码是:
```javascript
layui.use(['form'], function(){
var form = layui.form;
//全选
form.on('checkbox(selectAll)', function(data){
var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
child.each(function(index, item){
item.checked = data.elem.checked;
});
form.render('checkbox');
});
//子选项
form.on('checkbox(selectOne)', function(data){
var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
var flag = true;
child.each(function(index, item){
if(!item.checked){
flag = false;
}
});
if(flag){
$(data.elem).parents('table').find('thead input[type="checkbox"]').get(0).checked = true;
}else{
$(data.elem).parents('table').find('thead input[type="checkbox"]').get(0).checked = false;
}
form.render('checkbox');
});
});
```
希望能够帮到你!
阅读全文