用PHP代码怎样实现批量全选删除表单的数据
Admin 2022-09-17 群英技术资讯 1362 次浏览
这篇文章给大家分享的是“用PHP代码怎样实现批量全选删除表单的数据”,对大家学习和理解有一定的参考价值和帮助,有这方面学习需要的朋友,接下来就跟随小编一起学习一下吧。
<button type="button" class="btn btn-sm btn-danger btn-erbi-danger" id="batchDel" style="margin-right:20px;">批量删除</button>
<tr>
<th><input id="checkAll" type="checkbox"></th>
<th>ID</th>
<th>所属公司</th>
<th>姓名</th>
<th>性别</th>
<th>身份证号</th>
<th>手机号</th>
<th>住址</th>
<th>备注</th>
<th>标签</th>
<th>创建时间</th>
<th>操作</th>
</tr>
<volist name="result" id="vo">
<tr data-id="{$vo.id}" data-table="company">
<td><input class="checkOne" type="checkbox" data-id="{$vo.id}"></td>
<td>{$vo.id}</td>
<td>{$vo.company_name}</td>
<td>{$vo.name}</td>
<td>{$vo.sex_str}</td>
<td>{$vo.id_card}</td>
<td>{$vo.telephone}</td>
<td>{$vo.address}</td>
<td>{$vo.remark}</td>
<td>{$vo.tag_str}</td>
<td>{$vo.create_time|date='Y-m-d H:i',###}</td>
<td>
<?php if (!$_SESSION['_admin_is_company']) { ?>
<a href="javascript:;" class="info_tag">标签</a>
<?php }?>
<a href="javascript:;" data-id="{$vo.id}" class="info_edit">编辑</a>
<a href="javascript:;" data-id="{$vo.id}" class="info_del">删除</a>
</td>
</tr>
</volist>
一个checkAll,一个checkOne。一个ID,一个Class。
// 全选,反选
$("#checkAll").on('change', function () {
if ($(this).is(":checked")) { // 全选
$(".checkOne").prop("checked",true);
} else { // 反选
$(".checkOne").prop("checked",false);
}
});
// 批量删除
$("#batchDel").on('click', function () {
var ids = [];
// 获取选中的id
$('tbody input.checkOne').each(function (index, el) {
if ($(this).prop('checked')) {
ids.push($(this).data('id'))
}
});
layer.confirm('确认要删除吗?' + ids.toString(), function (index) {
//捉到所有被选中的,发异步进行删除
ajaxBatchDel(ids.toString());
});
});
// ajax批量删除
function ajaxBatchDel(ids) {
// ajax设置不通过
$.ajax({
type: 'POST',
url: 'ajaxBatchDel',
data: {ids: ids},
dataType: 'json',
success: function (data) {
if (data.errno == 0) {
layer.msg('删除成功', {icon: 1});
$(".checkOne:checked").parents('tr').remove();
} else {
layer.msg(data.errdesc, {icon: 5});
return false;
}
}
});
}
public function ajaxBatchDel() {
$ids = $_POST['ids'];
if (!$ids){
$this->json->setErr(10001,'请选择要删除的内容');
$this->json->Send();
}
$employee = M('employee');
$flag = $employee->where(['id'=>['in',$ids]])->save(['status'=>0]);
if($flag){
$this->json->setErr(0, '删除成功');
$this->json->Send();
}else{
$this->json->setErr(10099, '删除失败');
$this->json->Send();
}
}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
Redis是一种支持key-value等多种数据结构的存储系统,能够用于缓存,时间发布或者订阅等等。现在有很多大型网站会运用redis缓存,这能够明显提高网站速度。这篇文章就主要给大家介绍PHP操作Redis命令,感兴趣的朋友就继续往下看吧。
下面由phpstorm教程栏目给大家介绍Phpstorm-限制加载文件,希望对需要的朋友有所帮助!
PHP pthread拓展使用和注意点有哪些,一些朋友可能会遇到这方面的问题,对此在下文小编向大家来讲解一下,内容详细,易于理解,希望大家阅读完这篇能有收获哦,有需要的朋友就往下看吧!
PHP如何读取邮箱?这里会使用到POP3,下面是PHP使用POP3读取邮箱接收邮件的示例代码,以及对常用的POP3命令的介绍,感兴趣的朋友就继续往下看吧。
其中,Redis常见的报错就是:Redis可以配置如果客户端经过多少秒还不给Redis服务器发送数据,那么就会把连接close掉;MySQL常见的报错:和Redis服务器一样,MySQL也会定时的去清理掉没用的连接。
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 ICP核准(ICP备案)粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008