其他分享
首页 > 其他分享> > js checkbox

js checkbox

作者:互联网

var ids = new Array();
var table_data = new Array();
//复选框选中监听,将选中的id 设置到缓存数组,或者删除缓存数组
table.on('checkbox(shopinfo)', function (obj) {
    if (obj.checked == true) {
        if (obj.type == 'one') {
            if ($.inArray(obj.data.rowKey, ids) < 0) {
                ids.push(obj.data.rowKey);
            }
        } else {
            for (var i = 0; i < table_data.length; i++) {
                if ($.inArray(obj.data.rowKey, ids) < 0) {
                    ids.push(table_data[i].rowKey);
                }
            }
        }
    } else {
        if (obj.type == 'one') {
            for (var i = 0; i < ids.length; i++) {
                if (ids[i] == obj.data.rowKey) {
                    ids.splice(i, 1);
                }
            }
        } else {
            for (var i = 0; i < ids.length; i++) {
                for (var j = 0; j < table_data.length; j++) {
                    if (ids[i] == table_data[j].rowKey) {
                        ids.splice(i, 1);
                    }
                }
            }
        }
    }
});

<div class="layui-fluid">
    <div class="layui-col-md12" id="table_area">
        <table class="layui-table" id="table_shop" lay-filter="shopinfo"></table>
    </div>
</div>

 

标签:checkbox,obj,ids,js,rowKey,var,table,data
来源: https://www.cnblogs.com/luweiweicode/p/15242435.html