layui实现复选框全选,反选

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);
    })

 

posted @ 2018-08-23 15:17  下页、再停留  阅读(5606)  评论(0编辑  收藏  举报