checkbox几种全选的方法

 
<html>

<body>

<input type=checkbox name=chk>
<input type=checkbox name=chk>
<input type=checkbox name=chk>
<input type=checkbox name=chk>
<input type=checkbox name=chk>
<br>
全选:<input type=checkbox οnclick=sel('chk')>
<script language="javascript">
 function sel(a){
  o=document.getElementsByName(a)
  for(i=0;i<o.length;i++)
  o[i].checked=event.srcElement.checked
 }
</script>
--------------------------\
checkbox全选<head></head>

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;}
checkflag = "true";
return "false"; }
else {
for (i = 0; i < field.length; i++) {
field[i].checked = false; }
checkflag = "false";
return "true"; }
}
//  End -->
</script>

<body></body>
<form name="frm" method="post" action="">

 


                  选中所有显示记录
          ---------------------------------------------------------------<br>

<input type="checkbox" οnclick="CCA(this.form,this)" name="list" value="3">
<input type="checkbox" οnclick="CCA(this.form,this)" name="list" value="3">
<input type="checkbox" οnclick="CCA(this.form,this)" name="list" value="3">
<input type="checkbox" οnclick="CCA(this.form,this)" name="list" value="3">
<input type="checkbox" οnclick="CCA(this.form,this)" name="list" value="3">
<input type="checkbox" οnclick="CCA(this.form,this)" name="list" value="3">
<input type="checkbox" οnclick="CCA(this.form,this)" name="list" value="3">
<input type="checkbox" οnclick="CCA(this.form,this)" name="list" value="3">
<input type="checkbox" οnclick="CCA(this.form,this)" name="list" value="3">
<input type="checkbox" οnclick="CCA(this.form,this)" name="list" value="3">
<input type="checkbox" οnclick="CCA(this.form,this)" name="list" value="3">
<input type="checkbox" οnclick="CCA(this.form,this)" name="list" value="3">
<input type="checkbox" οnclick="CCA(this.form,this)" name="list" value="3">
<input type="checkbox" οnclick="CCA(this.form,this)" name="list" value="3">
<input type="checkbox" οnclick="CCA(this.form,this)" name="list" value="3">
<input type="checkbox" οnclick="CCA(this.form,this)" name="list" value="3">
<input type="checkbox" οnclick="CCA(this.form,this)" name="list" value="3">
<input type="checkbox" οnclick="CCA(this.form,this)" name="list" value="3">
<input type="checkbox" οnclick="CCA(this.form,this)" name="list" value="3">
<input type="checkbox" οnclick="CCA(this.form,this)" name="list" value="3">
<input type="checkbox" οnclick="CCA(this.form,this)" name="list" value="3">
<input type="checkbox" οnclick="CCA(this.form,this)" name="list" value="3">
----
<input type="checkbox" οnclick="CA(this.form)" name="allbox" value="allbox">
+===
<input type="checkbox" name="list2" value="3">
          </form>
   
<script language="javascript">
<!--

function CA(frm)
{
    alert(frm.allbox.value);
var trk=0;
for (var i=0;i<frm.elements.length;i++)
{
var e=frm.elements[i];
if ((e.name != 'allbox') && (e.type=='checkbox') && (e.name != 'list2'))
{
trk++;
e.checked=frm.allbox.checked;
//frm.del.disabled = frm.allbox.checked?false:true;//全选对删除按钮的disabled属性的影响
}
}
}

function CCA(frm,CB)
{
    alert(CB.checked);
var TB=TO=0;
for (var i=0;i<frm.elements.length;i++)
{
var e=frm.elements[i];
if ((e.name != 'allbox') && (e.type=='checkbox') && (e.name != 'list2'))
{
TB++;
if (e.checked)
TO++;
}
}
frm.allbox.checked=(TO==TB)?true:false;

if (0==TO)//全部未选中和选中一些时对删除按钮的disabled属性的影响
{
//frm.del.disabled = true;
}
else
{
//frm.del.disabled = false;
}
}

-->
</script>
         
</body>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值