微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

layui全选,单选checkbox

layui全选,单选(checkBox

js监听

/**
 * 全选
 * @param val
 * @constructor
 */
layui.use(['form'], function(){
    var form = layui.form();
    //全选
    form.on('checkBox(allChoose)', function (data) {
        $("input[name='check[]']").each(function () {
            this.checked = data.elem.checked;
        });
        form.render('checkBox');
    });
    //单选
    form.on('checkBox(oneChoose)', function (data) {
        var i = 0;
        var j = 0;
        $("input[name='check[]']").each(function () {
            if( this.checked === true )
            {
                i++;
            }
            j++;
        });
        if( i == j )
        {
            $(".checkBoxAll").prop("checked",true);
            form.render('checkBox');
        }else
        {
            $(".checkBoxAll").removeAttr("checked");
            form.render('checkBox');
        }

    });
});

 Html

<tr>
 <th width="40" ><input type="checkBox" class="checkBoxAll" lay-skin="primary"  lay-filter="allChoose" ></th>
 <th width="210">商品名称</th>
 <th width="160">SKU</th>
 <th width="70">产品类型</th>
 <th width="140">价格(元)</th>
 <th width="140">发布时间</th>
 <th>操作</th>
</tr>
<tr>
   <td><input type="checkBox" name="check[]" value="2" lay-skin="primary" lay-filter="oneChoose"></td>
   <td></td>
   <td></td>
   <td></td>
   <td></td>
   <td></td>
</tr>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐