<input type=checkbox name=mm value=a><br>
<input type=checkbox name=mm value=b><br>
<input type=checkbox name=mm value=c><br>
<input type=checkbox name=mm value=d><br>
<input type=checkbox name=mm value=e><br><br>
<input type=checkbox name=mmAll>全选与不全选的切换
<script language=Javascript>
function checkAll(e, itemName)
{
var aa = document.getElementsByName(itemName);
for (var i=0; i<aa.length; i++)
aa[i].checked = e.checked;
}
function checkItem(e, allName)
{
var all = document.getElementsByName(allName)[0];
if(!e.checked) all.checked = false;
else
{
var aa = document.getElementsByName(e.name);
for (var i=0; i<aa.length; i++)
if(!aa[i].checked) return;
all.checked = true;
}
}
</script>
ps:(当然若那个全选框是其它的控件比如是一个按钮,或者一个链接什么的话,那复选框里的 checkItem 点击事件可以去掉,以免出错)