新手贴一段完整版本的批量删除代码,高手匆喷

浏览:2381 发布日期:2014/10/02 分类:功能实现 关键字: 批量删除 代码交流 thinkphp
批量删除操作在于高手而言自然不在话,对于初级水平的人来说确实有点费劲,下面贴一段有关批量操作的全套代码,旨在抛砖引玉,共同提高!
前台代码:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html" />
<meta name="author" content="铁军科技" />
<meta charset="utf-8" />
<link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
<title>无标题 5</title>
</head>

<body>
<table class="table table-hover">
<caption>悬停表格布局</caption>
<thead class="color:red;font-size:1.2em;">
<tr class="success"><form method="post" action="__URL__/del_all" >
<th><input type="checkbox" id="checkall"/></th>
<th>编号</th>
<th>名称</th>
<th>城市</th>
<th>密码</th>
<th>时间</th>
<th>操作</th>
</tr>
</thead>
<volist name="info" id="vo">
<tbody>
<tr class="warning">
<td><input type="checkbox" name="id[]" value="{$vo.id}"/></td>
<td> {$vo.id}</td>
<td>{$vo.test1};</td>
<td>{$vo.test2};</td>
<td>{$vo.test3};</td>
<td>{$vo.create_time|date="Y-m-d H:i:s",###}</td>
<td><a href="__URL__/edit/id/{$vo.id}">修改</a>
<a href="__URL__/del/id/{$vo.id}">删除</a>

</td>
</tr>
</tbody>

</volist>

</table>
<input type="submit" class="btn btn-success" value="批量删除"/>
</form>
<script>
$(function(){
$("#checkall").click(function(){
if($("#checkall").prop("checked")){
$(":checkbox").prop("checked",true);
}else{
$(":checkbox").prop("checked",false);
}

})

})
</script>
</body>
</html>
后台:
public function del_all($ids=array()){
if (IS_POST){
$ids=$_POST['id'];
// print_r($ids);exit;
$where['id']=array("in",$ids);
$result=M('test')->where($where)->delete();
if($result){
$this->success('操作成功!');
}else{
$this->error('操作失败!');
}
}
}
评论() 相关
后面还有条评论,点击查看>>