基于ThinkPHP實現(xiàn)批量刪除
更新時間:2015年12月18日 17:16:30 作者:天空還下著雪
這篇文章主要介紹了基于ThinkPHP實現(xiàn)批量刪除的代碼實例,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例分析了基于ThinkPHP實現(xiàn)批量刪除的代碼實例,分享給大家供大家參考,具體如下:
廢話不多說,先上效果圖:

HTML布局(基于bootstrap)
<div class="panel panel-default">
<div class="panel-heading">
留言列表
<a class="btn btn-xs btn-default pull-right" href="javascript:window.history.back();">返回</a>
<a class="btn btn-xs btn-info pull-right mr-5" id="discard" href="javascript:;">刪除</a>
</div>
<table class="table">
<thead>
<tr>
<th><input class="all" type="checkbox"/></th>
<th>id</th>
<th>名稱</th>
<th>郵箱</th>
<th>內容</th>
<th>日期時間</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<form>
<volist name="list" id="vo" empty="$empty">
<tr>
<td><input name="delete[]" type="checkbox" value="{$vo.id}" /></td>
<td>{$vo.id}</td>
<td>{$vo.name}</td>
<td>{$vo.email}</td>
<td>{$vo.subject}</td>
<td>{$vo.datetime|date="Y-m-d H:i", ###}</td>
<td>
<a class="delete" href="javascript:;" data-id="{$vo.id}">刪除</a>
</td>
</tr>
</volist>
</form>
</tbody>
</table>
</div>
JS腳本處理(使用ajax技術)
首先判斷有沒有選中的值,如果沒有則提示;如果有,則傳遞到服務器端處理
/* 批量刪除 */
// 全選
$('.all').click(function() {
if($(this).is(':checked')) {
$(':checkbox').attr('checked', 'checked');
} else {
$(':checkbox').removeAttr('checked');
}
});
// 刪除操作
$('#discard').click(function() {
if($(':checked').size() > 0) {
layer.confirm('確定要刪除嗎?', {
btn: ['確定','取消'], //按鈕
shade: false //不顯示遮罩
}, function(){
$.post("{:U('Single/discard')}", {data: $('form').serializeArray()}, function(res) {
if(res.state == 1) {
layer.msg(res.message, {icon: 1, time: 1000});
} else {
layer.msg(res.message, {icon: 2, time: 1000});
}
setTimeout(function() {
location.reload();
}, 1000);
});
}, function(){
layer.msg('取消了刪除!', {time: 1000});
});
} else {
layer.alert('沒有選擇!');
}
});
PHP代碼:
獲取提交的數(shù)據(jù),然后循環(huán)得到每一個id的值,接著進行刪除操作。
public function discard() {
$contact = M('contact');
$deleteArr = I('post.data');
for($i=0;$i<count($deleteArr);$i++) {
$contact->delete($deleteArr[$i]['value']);
}
$this->ajaxReturn(array('message'=>'刪除成功!'));
}
以上就是ThinkPHP實現(xiàn)批量刪除的關鍵性代碼,希望對大家的學習有所幫助。
您可能感興趣的文章:
- ThinkPHP實現(xiàn)一鍵清除緩存方法
- ThinkPHP緩存方法S()概述
- thinkphp緩存技術詳解
- 修改ThinkPHP緩存為Memcache的方法
- Thinkphp關閉緩存的方法
- ThinkPHP靜態(tài)緩存簡單配置和使用方法詳解
- ThinkPHP實現(xiàn)靜態(tài)緩存和動態(tài)緩存示例代碼
- ThinkPHP簡單使用memcache緩存的方法
- ThinkPHP框架中使用Memcached緩存數(shù)據(jù)的方法
- ThinkPHP實現(xiàn)批量刪除數(shù)據(jù)的代碼實例
- thinkPHP批量刪除的實現(xiàn)方法分析
- TP5(thinkPHP框架)實現(xiàn)后臺清除緩存功能示例
相關文章
php實現(xiàn)按照權重隨機排序數(shù)據(jù)的方法
這篇文章主要介紹了php實現(xiàn)按照權重隨機排序數(shù)據(jù)的方法,是php數(shù)據(jù)排序中一個比較典型的應用技巧,需要的朋友可以參考下2015-01-01
淺析PHP substr,mb_substr以及mb_strcut的區(qū)別和用法
本篇文章是對PHP中的substr,mb_substr以及mb_strcut區(qū)別和用法進行了詳細的分析介紹,需要的朋友參考下2013-06-06

