<button id="dels">批量删除</button>
<td> <input type="checkbox" class="del" ids="{$val['id']}"> </td>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script> <script> $('#dels').click(function(){ var data = $('.del:checked'); var ids = ''; $.each(data,function (i,v){ ids += ','+$(v).attr('ids'); }) ids = ids.substr(1); $.ajax({ url:'del', data:{ids:ids}, success:function (res){ location.href='show'; } }) }) </script>
控制器
public function del($ids) { $delRes = \app\model\show::del($ids); if ($delRes){ return json(['code'=>200,'msg'=>'成功']); }else{ return json(['code'=>200,'msg'=>'成功']); } //dd($ids); }
模型层
public static function delOne($id,$state = false) { return self::destroy($id,$state); }
//批量删除
public static function del($id) { return self::where('id',$id)->delete(); }