//全選 function allSelect(){ $('.td_chk :checkbox').attr('checked',true); } //反選 function unSelect(){ $('.td_chk :checkbox').attr('checked',false); } //刪除 function del(){ var num = $(".chkbox:checked").length; //選中個數(全部checkbox的class均爲.chkbox) var data = new Array(); //聲明數組 if(num){ $('.chkbox:checked').each(function(){ data.push($(this).val()); //循環插入數組數據 }) if(confirm('肯定要刪除如下多條數據?'+data)){ $.ajax({ url:'<?php echo site_url(CFG_CMSPATH.'article/delrow')?>', //這是CI寫的提交的頁面URL data:({aid:data.join()}), //data.join是合併成一個字符串,不然提交的將是數組 success:function(){ window.location.reload(); //成功後,刷新頁面 } }) } } }
php代碼:
控制器:
php
public function delrow($aid=''){ if($aid){ //用與刪除單調數據的 $this->where['aid'] = $aid; $this->model->delete($this->where); redirect($_SERVER['HTTP_REFERER']); }else{ if(isset($_GET['aid'])): //刪除多條數據 $this->where['in_aid'] = $_GET['aid']; $this->model->delete($this->where); endif; } }
備註:
詳細的刪除方法都寫在模型裏了,用的是 delete from tab where aid in ()
ajax