javascript实现全选全不选

<table border="1">

<tr>

#遍历出数据

<?php foreach($data  as  $k=>$v) {?>

     <td><input type="checkbox" value="<?php echo $id?> "></td>

     <td><input type="checkbox" value="<?php echo $id?> "></td>

     <td><input type="checkbox" value="<?php echo $id?> "></td>

     <td><input type="checkbox" value="<?php echo $id?> "></td>

     <td><input type="checkbox" value="<?php echo $id?> "></td>

     <td><a href="javascript:void(0)"   οnclick="del(this,<?php echo $id?> )">删除</a></td>

</tr>

<?php }?>

<button        οnclick="all_select( true )">全选</button>

<button        οnclick="un_select(  )">反选</button>

<button        οnclick="all_select( false )">全不选</button>

<button        οnclick="all_del(  )">批量删除</button>

<script>

function all_select(bool)

{

var box=document.getElementByTagName('input');

for( var i=0;i<box.length;i++)

{

box[i].checked==bool;

}

}

function      un_select()

{

var box=document.GetElementByTagName('input');

for(var i=0;i<box.length;i++)

{

if(box[i].checked==true)

else{

box[i].checked==false;

}else{

box[i].checked=true;

}

}

}

function del(th,id)

{

var is=confirm("确认删除吗?");

if(is==true)

{

location.href="del.php?id="+id

}

}

function all_del()

{

if(confirm("您确认删除吗"))

{

var checkbox=document.getElementByTagName("input");

var  ids='   ';

for(var i=0;i<checkbox.length;i++)

{

if(checked[i].checked)

{

ids+=checked[i].value+','

}

}

location.href="del.php?id="+ids

}


}

</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值