一、form表单的情况
<html>
<head>
<script language="javascript" type="text/javascript">
function CheckAll(form1){
for(var i=0;i<form.elements.length;i++){
var e = form1.elements[i];
if(e.name != 'chkall'){
e.checked = form1.chkall.checked;
}
}
}
</script>
</head>
<body>
<form action="" name="form">
<input type="checkbox" name="chkall" value="on" οnclick="CheckAll(this.form)" />全选
<input name="toDelGWCProID" type="checkbox" />
<input name="toDelGWCProID" type="checkbox" />
<input name="toDelGWCProID" type="checkbox" />
<input name="toDelGWCProID" type="checkbox" />
</form>
</body>
</html>
二、没有表单的情况 不能适应一个按钮的情况
<html>
<head>
<script language="javascript" type="text/javascript">
function CheckAll(form1){
var len = document.getElementsByName("toDelGWCProID");
if(len.length){
for(var i=0;i<len.length;i++){
len[i].checked = form.checked;
}
}else{
len[0].checked = form.checked;
} }
</script>
</head>
<body>
<input type="checkbox" name="chkall" value="on" οnclick="CheckAll(this.form)" />全选
<input name="toDelGWCProID" type="checkbox" />
<input name="toDelGWCProID" type="checkbox" />
<input name="toDelGWCProID" type="checkbox" />
<input name="toDelGWCProID" type="checkbox" />
</body>
</html>