//父选择框 <input type="checkbox" id="check_all"> //子选择框 <input type="checkbox" class="checked_id" name="checked_id[]"> //jquery实现多选 $('#check_all').click(function () { // prop() 方法设置或返回被选元素的属性和值 $(':checkbox').prop("checked", this.checked); }) //ajax多选删除 $('.del_all').click(function () { // alert(123); var length = $('.checked_id:checked').length; if (length == 0) { alert('请至少选择一条记录!'); return false; } //序列化元素获取多条记录 var check_id = $('.checked_id:checked').serialize(); // console.log(check_id); //ajax传递到后台 $.ajax({ type: 'post', url: "{{:U('delete_all')}}", data: check_id, success: function (data) { if (data.status == 1) { alert(data.msg); $('.checked_id:checked').each(function () { $(this).parents('tr').remove() }) } } }) }) //TP3.2实现多选删除 public function delete_all() { if (IS_AJAX) { // dump($_POST);exit(); //接收到所有选中的id $checked_ids = I('post.checked_id'); //通过循环依次进行删除 foreach ($checked_ids as $value) { $this->product->where("id = '$value'")->setField('is_history', 1); } $info = [ 'status' => 1, 'msg' => '选择的商品成功移至回收站' ]; $this->ajaxReturn($info); } }
TP3.2-ajax多选操作(删除)
最新推荐文章于 2024-05-06 11:22:20 发布