预览地址:http://www.gold98.net/blog/upfile/testchecked.html
下面只是实现利用javascript实现复选框全选的一种方法,还有其它很多方法,这就需要大家慢慢探索了~
<script language="javascript">
function chkAll_onclick(){
if(typeof(form1.chkAccount) == "object"){
if(form1.chkAllAccount.checked){
SelAll();
}
else{
unSelAll();
}
}
}
function SelAll(){
var intCount;
var result="";
if(form1.all("chkAccount").length > 1)
{
for(intCount = 0; intCount < form1.all("chkAccount").length; intCount++)
{
form1.chkAccount(intCount).checked = true;
result=result+form1.chkAccount(intCount).value+";";
}
}
else{
form1.chkAccount.checked = true;
}
alert("你选中的是:"+result);
}
function unSelAll(){
var intCount;
if(form1.all("chkAccount").length > 1)
{
for(intCount = 0; intCount < form1.all("chkAccount").length; intCount++)
{
form1.chkAccount(intCount).checked = false;
}
}
else{
form1.chkAccount.checked = false;
}
}
</script>
<form name="form1" method="post" action="">
<input name="chkAccount" type="checkbox" value="人民"/>人民
<input name="chkAccount" type="checkbox" value="中国"/>中国
<input name="chkAccount" type="checkbox" value="你好"/>你好
<input name="chkAccount" type="checkbox" value="公园"/>公园
<input name="chkAccount" type="checkbox" value="长江"/>长江
<input name="chkAccount" type="checkbox" value="黄河"/>黄河
<input type="checkbox" name="chkAllAccount" value="ON" title="全部选中" onclick="chkAll_onclick()">全部选中
</form>