当checkbox只有一个时,全选错出了!
<script type="text/javascript"> // 说明:Javascript 控制 CheckBox 的全选与取消全选
//<!-- Begin
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;}
checkflag = "true";
return "false"; }
else {
for (i = 0; i < field.length; i++) {
field[i].checked = false; }
checkflag = "false";
return "true"; }
}
// End -->
</script>
<form>
<input id="chkAll" name="chkAll" type="checkbox" onClick="this.value=check(this.form.chkMember)" /> 全选<br/>
<input name="chkMember" type="checkbox" value="38" title="蔡登峰" />蔡登峰
</form>