jquery批量删除
生活随笔
收集整理的這篇文章主要介紹了
jquery批量删除
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
前臺代碼
<!doctype html> <html lang="en"> <head><meta charset="UTF-8"><meta name="viewport"content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Document</title> </head> <body> <table><tr><td>ID</td><td>房東</td><td>租客</td><td>預約時間</td><td>內(nèi)容</td><td>操作</td></tr>@foreach($data as $v)<tr><td><input type="checkbox" class="check" value="{{$v->id}}"></td><td>{{$v->id}}</td><td>{{$v->name}}</td><td>{{$v->zuke}}</td><td>{{$v->time}}</td><td>{{$v->content}}</td><td><button class="btn" value="{{$v->id}}">刪除</button></td></tr>@endforeach </table> <button class="delall">刪除選中的</button> </body> </html> <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script><script>$(function () {$(".btn").click(function () {let id = $(this).attr('value');//發(fā)送ajaxvar _this = $(this);$.ajax({url:"http://www.homework.com/index.php/fangdel?id="+id,success:function (res) {if(res.code == 200){$(_this).parent('td').parent('tr').remove();}}})});$(".delall").click(function () {//獲取選中的id//首先定義一個數(shù)組var fang_id = [];$('.check:checked').each(function (i,v) {fang_id.push($(v).val());})//將數(shù)組分割成字符串fang_id = fang_id.join(',');console.log(fang_id);//發(fā)送ajax$.ajax({url:"{{route('fangdelall')}}",data:{fang_id:fang_id},success:function (res) {if(res.code == 200){$('.check:checked').each(function(i,v){$(v).parents('tr').remove();})}}})});}) </script>**
后臺代碼
**
//單刪除public function fangdel(Request $request){$id = $request->input('id');//刪除數(shù)據(jù)if (Fang::destroy($id)){return ['code' => 200,'msg'=>'ok','data' => []];}}//批刪除public function fangdelall(Request $request){//接收參數(shù)$fang_id = $request->input();$fang_id = implode(',',$fang_id);$fang_id = explode(',',$fang_id);if (Fang::destroy($fang_id)){return ['code' => 200,'msg' => 'ok','data'=>[]];}}總結(jié)
以上是生活随笔為你收集整理的jquery批量删除的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: error记录 | 不能将参数 1 从“
- 下一篇: doip 源码_DoIP技术(一)