基于ThinkPHP实现批量删除,
本文实例分析了基于ThinkPHP实现批量删除的代码实例,分享给大家供大家参考,具体如下:
废话不多说,先上效果图:
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代码:
获取提交的数据,然后循环得到每一个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实现批量删除的关键性代码,希望对大家的学习有所帮助。
您可能感兴趣的文章:
- php批量删除数据
- PHP 批量删除 sql语句
- PHP 批量删除数据的方法分析
- php中批量删除Mysql中相同前缀的数据表的代码
- PHP批量删除、清除UTF-8文件BOM头的代码实例
- ThinkPHP实现批量删除数据的代码实例
- php批量删除数据库下指定前缀的表以prefix_为例
- php批量删除cookie的简单实现方法

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.