layui实现复选框全选,反选
程序员文章站
2022-10-04 22:43:49
html js ......
html
<div class="layui-input-inline"> <input type="checkbox" class="checkboxall" lay-skin="primary" lay-filter="allchoose" title='全选'> </div>
<input type="checkbox" name="check[]" value="{$item.id}" lay-skin="primary" title="{$item.type_name}" lay-filter="onechoose">
<input type="button" id="sub" class="layui-btn" value="确认添加">
js
layui.use(['layer','form'], function () { var form = layui.form ,layer = layui.layer; form.on('checkbox(allchoose)', function (data) { $("input[name='check[]']").each(function () { this.checked = data.elem.checked; // console.log(data); }); form.render('checkbox'); }); }); $('#sub').click(function(){ var items =[]; $("input[name='check[]']:checked").each( function(){ items.push($(this).val()); }) console.log(items); })