我这有个现成的例子
<SCRIPT language=javascript>
function unselectall()
{
if(document.myform.chkAll.checked){
document.myform.chkAll.checked = document.myform.chkAll.checked&0;
}
}
function CheckAll(form)
{
for (var i=0;i<form.elements.length;i++)
{
var e = form.elements[i];
if (e.Name != "chkAll"&&e.disabled==false)
e.checked = form.chkAll.checked;
}
}
</SCRIPT>
<form name="myform" method="Post" action="">
<tr class="title" height="22">
<td height="22" width="30" align="center"><strong>选中</strong></td>
<td height="22" width="30" align="center"><strong>姓名</strong></td>
</tr>
<tr class="tdbg" onmouseout="this.style.backgroundColor=''" onmouseover="this.style.backgroundColor='#BFDFFF'">
<td width="30" align="center"><input name='ID' type='checkbox' onclick="unselectall()" id="ID" value='1'></td>
<td width="25" align="center">张三</td>
</tr>
</table>
<br>
<table width="99%" border="0" cellpadding="0" cellspacing="0" class="tdbg" align=center>
<tr>
<td width="250" height="30"><input name="chkAll" type="checkbox" id="chkAll" onclick=CheckAll(this.form) value="checkbox">
选中本页显示的所有 </td>
</tr>
</table>