<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script language="javascript" type="text/javascript">
window.onload=function(){
var CheckAll=document.getElementById('All');
var UnCheck=document.getElementById('uncheck');
var reverseCheck=document.getElementById('reverseCheck');
var div=document.getElementById('div');
var CheckBox=div.gteElementsByTagName('input');
CheckAll.onclick=function(){
for(var i=0;i<CheckBox.length;i++)
CheckBox[i].checked=true;
};
};
UnCheck.onclick=function(){
for(i=0;i<CheckBox.length;i++)
MeCheckBox[i].checked=false;
};
};
reverseCheck.onclick=function(){
for(i=0;i<CheckBox.length;i++){
if(CheckBox[i].checked==true){
CheckBox[i].checked=false;
}else{
CheckBox[i].checked=true;
};
};
};
};
</script>
</head>
<body>
全选:<input type="button" id="All" value="全选"/><br/>
不选:<input type="button" id="uncheck" value="不选"/><br/>
反选:<input type="button" id="reverseCheck" value="反选"/><br/>
<div id="div">
<input type="Checkbox"/><br/>
<input type="Checkbox"/><br/>
<input type="Checkbox"/><br/>
<input type="Checkbox"/><br/>
<input type="Checkbox"/><br/>
<input type="Checkbox"/><br/>
<input type="Checkbox"/><br/>
<input type="Checkbox"/><br/>
<input type="Checkbox"/><br/>
</div>
</body>
</html>
var CheckBox=div.gteElementsByTagName('input');这里写错了吧
额,谢谢啊,可是改过来了还是不对,不知道咋回事,,,可以了,你改了哪里
@疯狂的兔子!:
<script language="javascript" type="text/javascript"> window.onload = function() { var CheckAll = document.getElementById('All'); var UnCheck = document.getElementById('uncheck'); var reverseCheck = document.getElementById('reverseCheck'); var div = document.getElementById('div'); var CheckBox = div.getElementsByTagName('input'); CheckAll.onclick = function() { for (var i = 0; i < CheckBox.length; i++) CheckBox[i].checked = true; } UnCheck.onclick=function(){ for(i=0;i<CheckBox.length;i++) CheckBox[i].checked = false; } reverseCheck.onclick=function(){ for(i=0;i<CheckBox.length;i++){ if(CheckBox[i].checked==true){ CheckBox[i].checked=false; }else{ CheckBox[i].checked=true; }; }; } } </script>
这样试下
@jello chen: 改了哪里啊
@疯狂的兔子!:
改了如下几个地方:
1.var CheckBox = div.getElementsByTagName('input');
2.MeCheckBox[i].checked=false;
3.去掉了两个};
4.将UnCheck.onclick和reverseCheck.onclick放到了window.onload中了
@jello chen: 谢谢啊,哈哈,for循环后面忘记加大括号了