<script language="JavaScript">
<!--
function chkClk(obj){
var chks=document.getElementsByName(obj.name);
//alert(chks.length);
if(obj.flag=="main"){
for(var i=1;i<chks.length;i++)
chks[i].checked=obj.checked;
}
else{
for(var i=1;i<chks.length;i++)
if(chks[i].checked==false){
chks[0].checked=false;
break;
}
else{
if(i==chks.length-1) chks[0].checked=true;
}
}
}
//-->
</script><input type="checkbox" onclick="chkClk(this)" name="type1" flag="main">typetext
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li>
<br><br>
<input type="checkbox" onclick="chkClk(this)" name="type2" flag="main">typetext
<li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li>
<!--
function chkClk(obj){
var chks=document.getElementsByName(obj.name);
//alert(chks.length);
if(obj.flag=="main"){
for(var i=1;i<chks.length;i++)
chks[i].checked=obj.checked;
}
else{
for(var i=1;i<chks.length;i++)
if(chks[i].checked==false){
chks[0].checked=false;
break;
}
else{
if(i==chks.length-1) chks[0].checked=true;
}
}
}
//-->
</script><input type="checkbox" onclick="chkClk(this)" name="type1" flag="main">typetext
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li>
<br><br>
<input type="checkbox" onclick="chkClk(this)" name="type2" flag="main">typetext
<li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li>
var a = document.messagefrm.selectid;
if (obj.blnStatus ==1 ) {
for (var i=0; i<a.length; i++) {
a[i].checked = false;
}
obj.blnStatus =0;
}else {
for (var i=0; i<a.length; i++) {
a[i].checked = true;
}
obj.blnStatus =1;
}
}<a href="#" onclick="javascript:checkall(this);return false;">全选</a>
<!--
var flags=0;
function checkselect(obj)
{
if (flags==0)
{
for (var i=0; i<document.forms[0].type1.length;i++)
{
document.forms[0].type1[i].checked = true;
document.forms[0].selectA.value="取消选择";
flags=1;
}
}
else
{
for (var i=0; i<document.forms[0].type1.length;i++)
{
document.forms[0].type1[i].checked = false;
document.forms[0].selectA.value="全 选";
flags=0;
}
}
}
//-->
</script>
<body>
<form name="public">
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext12</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext11</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext10</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext9</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext8</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext7</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext6</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext5</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext4</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext3</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext2</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext1</li>
<input type="button" name="selectA" onclick="checkselect()" value="全 选">
</form>
</body>
<input name="fmTypeForSeek" type="checkbox" value="asp" checked="checked" />:asp<input name="fmTypeForSeek" type="checkbox" value="htm" />:htm<input name="fmTypeForSeek" type="checkbox" value="html" checked="checked" />:html<input name="fmTypeForSeek" type="checkbox" value="txt" checked="checked" />:txt<input name="fmTypeForSeek" type="checkbox" value="xml" checked="checked" />:xml
<input type="button" value="全选" onclick="fSelect('all','fmTypeForSeek')"/>
<input type="button" value="反选" onclick="fSelect('reverse','fmTypeForSeek')"/>
<input type="button" value="全不选" onclick="fSelect('reset','fmTypeForSeek')"/>
</div>
<script type="text/javascript">
//<![CDATA[ Subject: Javascript 复选框 全选, 反选, 全不选 函数 By shawl.qiu
function fSelect(str,iptName){
var gItem=document.getElementsByTagName('input')
for(i=0;i<gItem.length;i++){
if(gItem[i].name==iptName){
if (str=='all'){ gItem[i].checked=true;} //全选
//---------------------------------------------- start 反选
else if (str=='reverse'){
if(gItem[i].checked==false){gItem[i].checked=true;} //如果没有选中, 则设为选中
else{gItem[i].checked=false;} }//如果选中, 则设为没有选中
//---------------------------------------------- end 反选
else{ gItem[i].checked=false;} //全不选
}
}
}
//]]> shawl.qiu script
</script>
我用了他的了,方便