基于ThinkPHP實(shí)現(xiàn)批量刪除
本文實(shí)例分析了基于ThinkPHP實(shí)現(xiàn)批量刪除的代碼實(shí)例,分享給大家供大家參考,具體如下:
廢話不多說,先上效果圖:
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>內(nèi)容</th> <th>日期時(shí)間</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技術(shù))
首先判斷有沒有選中的值,如果沒有則提示;如果有,則傳遞到服務(wù)器端處理
/* 批量刪除 */ // 全選 $('.all').click(function() { if($(this).is(':checked')) { $(':checkbox').attr('checked', 'checked'); } else { $(':checkbox').removeAttr('checked'); } }); // 刪除操作 $('#discard').click(function() { if($(':checked').size() > 0) { layer.confirm('確定要?jiǎng)h除嗎?', { 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)得到每一個(gè)id的值,接著進(jìn)行刪除操作。
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實(shí)現(xiàn)批量刪除的關(guān)鍵性代碼,希望對(duì)大家的學(xué)習(xí)有所幫助。
- ThinkPHP實(shí)現(xiàn)一鍵清除緩存方法
- ThinkPHP緩存方法S()概述
- thinkphp緩存技術(shù)詳解
- 修改ThinkPHP緩存為Memcache的方法
- Thinkphp關(guān)閉緩存的方法
- ThinkPHP靜態(tài)緩存簡(jiǎn)單配置和使用方法詳解
- ThinkPHP實(shí)現(xiàn)靜態(tài)緩存和動(dòng)態(tài)緩存示例代碼
- ThinkPHP簡(jiǎn)單使用memcache緩存的方法
- ThinkPHP框架中使用Memcached緩存數(shù)據(jù)的方法
- ThinkPHP實(shí)現(xiàn)批量刪除數(shù)據(jù)的代碼實(shí)例
- thinkPHP批量刪除的實(shí)現(xiàn)方法分析
- TP5(thinkPHP框架)實(shí)現(xiàn)后臺(tái)清除緩存功能示例
相關(guān)文章
php實(shí)現(xiàn)按照權(quán)重隨機(jī)排序數(shù)據(jù)的方法
這篇文章主要介紹了php實(shí)現(xiàn)按照權(quán)重隨機(jī)排序數(shù)據(jù)的方法,是php數(shù)據(jù)排序中一個(gè)比較典型的應(yīng)用技巧,需要的朋友可以參考下2015-01-01解析PHP中empty is_null和isset的測(cè)試
本篇文章是對(duì)PHP中empty is_null和isse的測(cè)試進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06Ajax請(qǐng)求PHP后臺(tái)接口返回信息的實(shí)例代碼
今天小編就為大家分享一篇Ajax請(qǐng)求PHP后臺(tái)接口返回信息的實(shí)例代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-08-08淺析PHP substr,mb_substr以及mb_strcut的區(qū)別和用法
本篇文章是對(duì)PHP中的substr,mb_substr以及mb_strcut區(qū)別和用法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06