视图
<div id="rep">
<table border="1">
<tr>
<th>选择</th>
<th>id</th>
<th>内容</th>
<th>时间</th>
<th>url</th>
<th>操作</th>
</tr>
<?php foreach($arr as $v){ ;?>
<tr>
<td><input type="checkbox" name="chk" id="con" title="<?php echo $v['id'];?>"></td>
<td><?php echo $v['id'];?></td>
<td><?php echo $v['content'];?></td>
<td><?php echo $v['time'];?></td>
<td><?php echo $v['url'];?></td>
<td><a href="__APP__/Home/Index/del?id=<?php echo $v['id'];?>">删除</a></td>
</tr>
<?php }?>
<tr>
<td colspan="6">
全选<input type="checkbox" name="kkk" id="k" onclick="aa()">
反选<input type="checkbox" name="ddd" id="" onclick="bb()">
全不选<input type="checkbox" name="bbb" id="" onclick="cc()">
<input type="button" value="删除" style="margin-left:85px;" onclick="dels()">
</td>
</tr>
</table>
</div>
<script src="public/js/jquery.js"></script>
<script>
var chk = document.getElementsByName('chk');
function aa(){
for(var i=0; i<chk.length; i++){
chk[i].checked=true;
}
}
function bb(){
for(var i=0; i<chk.length; i++){
if(chk[i].checked){
chk[i].checked=false;
}else{
chk[i].checked=true;
}
}
}
function cc(){
for(var i=0; i<chk.length; i++){
if(chk[i].checked){
chk[i].checked=false;
}
}
}
function dels(){
var str='';
var box=document.getElementsByName('chk');
var aa=document.getElementById('aa');
for(var i=0;i<chk.length;i++){
if(chk[i].checked){
str=str+chk[i].title+',';
}
}
str=str.substring(str.length-1,',');
//alert(str);die;
var ajax=new XMLHttpRequest();
ajax.onreadystatechange=function(){
if(ajax.readyState==4){
document.getElementById('rep').innerHTML=ajax.responseText;
}
}
ajax.open('get','__APP__/Home/Index/dels?id='+str);
ajax.send(null);
}
</script>
控制器
<?php
// 本类由系统自动生成,仅供测试用途
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
public function index(){
$User = M("caiji");
$data = $User->select();
$this->assign('arr' ,$data);
$this->display('list');
}
public function del(){
$id = $_GET['id'];
$User = M("caiji");
$arr = $User->where("id=$id")->delete();
if($arr){
$this->success('删除成功',U('__APP__/Home/Index/index'));
}else{
$this->error('删除失败');
}
}
public function dels(){
$id = $_GET['id'];
$User = M("caiji");
$arr = $User->delete("$id");
$data = $User->select();
$this->assign('arr' ,$data);
$this->display('list');
}
}