layui的table做批量刪除實現(xiàn)代碼如下:
// 批量刪除功能 // 1.得到table選中行內(nèi)容 // 2.得到刪除需要的唯一值,一般是id; // 3.將所要刪除的項加入到數(shù)組中; // 4.判斷是否選中; // 5.發(fā)送ajax請求,并附帶參數(shù)id; var $=layui.$,active={ deLink:function () { var checkStatus=table.checkStatus('idTest'), data=checkStatus.data, deList=[]; data.forEach(function(n,i){ delList.push(n.id); }); if(delList!=''){ layer.comfirm('確定刪除所選項嗎?',function (index) { $.ajax({ url: '/cd/workPlatform/tool/remove.afca', type:'post', dataType:'json', data:"id="+delList, success:function (data,statusText) { if(data.code==='0'){ layer.msg('刪除成功'); table.reload('idTest',{}); }else{ layer.msg('刪除失敗'); } }, 'error':function () { layer.msg('系統(tǒng)錯誤'); } }) }) }else{ layer.tips('請選擇需要刪除的行',$('#batchDel'),{ tips:[3,'#5fb878'] }) } } }
推薦:layui框架教程