<button class="layui-btn layui-btn-danger" data-type="getid" οnclick="delAll()">删除所有选中行</button>
js:
table.on('checkbox(table)', function(obj){ var data = obj.data; }); layui.jquery, active = { getid: function () { var arr = []; var checkStatus = table.checkStatus('tableid') , data = checkStatus.data; for (var i = 0; i < data.length; i++) { //循环筛选出id arr.push(data[i].id); } $("#ids").val(arr); } } $('.layui-btn').on('click', function(){ var type = $(this).data('type'); active[type] ? active[type].call(this) : ''; });
function delAll(){ layer.confirm('确定删除吗?', {btn: ['确定删除', '取消']}, function (index) { var a1 = $("#ids").val(); //取得已获取的ids $.ajax({ ....... }); }); }