html代码
<!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>
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
</head>
<body>
<table class="table">
<th><button onclick="dell()">批量删除</button></th>
<th>ID</th>
<th>标题</th>
<th>名字</th>
<th>图片</th>
<th>操作</th>
{volist name="data" id="val"}
<tr>
<td><input type="checkbox" name="checkBoxGroup" value="{$val->id}"></td>
<td>{$val->id}</td>
<td>{$val->title}</td>
<td>{$val->name}</td>
<td><img src="http://www.hejialing.com/{$val->file}" alt="" width="30px"></td>
</tr>
{/volist}
</table>
{$data|raw}
</body>
</html>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js">
</script>
<script>
function dell() {
var str = '';
//获取多选框选中的id,循环赋值给str
$(":checkbox[name='checkBoxGroup']:checked").each(function() {
str += $(this).val() + ",";
});
//Ajax发送id进行删除
$.ajax({
url:'dell',
data:{
id:str,
},
dataType:'json',
success:function (res) {
if(res.code==200)
{
window.location.href='';
}
}
})
}
</script>
控制器代码
public function dell(Request $request)
{
$id=$request->param('id');
$obj=new mode();
$arr=$obj->dell($id);
if($arr)
{
return json(['code'=>200,'mes'=>'删除成功','data'=>[]]);
}
}
模型层代码
public function dell($id)
{
return $this->whereIn('id',$id)->delete();
}