Think5之ajax批量删除数据功能

本文介绍了一种批量删除学员信息的方法,通过PHP后端实现,包括处理单个和多个ID的删除逻辑,并提供了相应的前端页面展示及交互实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//批量删除学员信息
	public function deleteMany() {

		  $id = input('post.');  //判断id是数组还是一个数值 
		  if(is_array($id)){ 
			 foreach($id['data'] as $v){
			  	$ids[] = $v['value'];
			} 
		    $where = 'id in('.implode(',',$ids).')';  
		  }else{  
		   $where = 'id='.$id; 
		  }  
		  $list=model("students")->where($where)->delete();  
		  if($list==true) {
		    $this->success("成功删除{$list}条!"); 
		  }else{   
		    $this->error('批量删除失败!');  
		  } 
    }

<a href="javascript:;" id="del" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>

{volist name='studentsList' id='vo'}
<th width="15"><input type="checkbox" class="all" ></th>
<th width="30">ID号</th>
<th width="30">姓名</th>


<td><input name='id[]' type="checkbox" value="{$vo.id}"></td>
<td>{$vo.id}</td>
<td>{$vo.edu_name}</td>

{/volist}

  

// 删除操作js
  $('#del').click(function() {
    if($(':checked').size() > 0) {
      layer.confirm('确定要删除吗?', {
        btn: ['确定','取消'], //按钮
        shade: false //不显示遮罩
      }, function(){
        $.post("{:url('students/deleteMany')}",{data: $('form').serializeArray()}, function(data) {
          layer.msg('恭喜,已批量删除', {icon: 1, time: 1000});
          setTimeout(function() {
            location.reload();
          }, 1000);
        });
      }, function(){
        layer.msg('取消了删除!', {time: 1000});
      });
    } else {
      layer.alert('没有选择!');
    }
  });

  

转载于:https://www.cnblogs.com/qinglin/p/8692026.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值