javascript 复选框反选怎么做 正选可以了
<html><head></head><script>functioncheckAll(obj){varcks=document.getElementsByName("c...
<html>
<head>
</head>
<script>
function checkAll(obj){
var cks = document.getElementsByName("chkItem");
if(obj.checked){
for(var i=0;i<cks.length;i++){
cks[i].checked = true;
}
}else{
for(var i=0;i<cks.length;i++){
cks[i].checked = false;
}
}
}
</script>
<body>
<input type="checkbox" id="chkAll" onclick="checkAll(this);"/>全选
<input type="checkbox" id="chkAll" onclick="checkAll(this);"/>反选<br/>
<input type="checkbox" name="chkItem" />选项<br/>
<input type="checkbox" name="chkItem" />选项<br/>
<input type="checkbox" name="chkItem" />全选<br/>
<input type="checkbox" name="chkItem" />全选<br/>
<input type="checkbox" name="chkItem" />全选<br/>
<input type="checkbox" name="chkItem" />全选<br/>
</body>
</html> 展开
<head>
</head>
<script>
function checkAll(obj){
var cks = document.getElementsByName("chkItem");
if(obj.checked){
for(var i=0;i<cks.length;i++){
cks[i].checked = true;
}
}else{
for(var i=0;i<cks.length;i++){
cks[i].checked = false;
}
}
}
</script>
<body>
<input type="checkbox" id="chkAll" onclick="checkAll(this);"/>全选
<input type="checkbox" id="chkAll" onclick="checkAll(this);"/>反选<br/>
<input type="checkbox" name="chkItem" />选项<br/>
<input type="checkbox" name="chkItem" />选项<br/>
<input type="checkbox" name="chkItem" />全选<br/>
<input type="checkbox" name="chkItem" />全选<br/>
<input type="checkbox" name="chkItem" />全选<br/>
<input type="checkbox" name="chkItem" />全选<br/>
</body>
</html> 展开
1个回答
展开全部
<!DOCTYPE html>
<html>
<head>
<meta charset="gb2312">
<title></title>
<script>
window.onload = function(){
var obtn1 = document.getElementById('btn1');
var obtn2 = document.getElementById('btn2');
var obtn3 = document.getElementById('btn3');
var odiv = document.getElementById('div1');
var ocheck = odiv.getElementsByTagName('input');
obtn1.onclick = function(){ //全选
for(var i=0;i<ocheck.length;i++){
ocheck[i].checked = true;
}
};
obtn2.onclick = function(){ //不选
for(var i=0;i<ocheck.length;i++){
ocheck[i].checked = false;
}
};
obtn3.onclick = function(){ //反选
for(var i=0;i<ocheck.length;i++){
ocheck[i].checked = !ocheck[i].checked;
}
};
}
</script>
</head>
<body>
<input type="button" id="btn1" value="全选" />
<input type="button" id="btn2" value="不选" />
<input type="button" id="btn3" value="反选" />
<div id="div1">
<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 />
<input type="checkbox" /><br />
<input type="checkbox" /><br />
</div>
</body>
</html>
<html>
<head>
<meta charset="gb2312">
<title></title>
<script>
window.onload = function(){
var obtn1 = document.getElementById('btn1');
var obtn2 = document.getElementById('btn2');
var obtn3 = document.getElementById('btn3');
var odiv = document.getElementById('div1');
var ocheck = odiv.getElementsByTagName('input');
obtn1.onclick = function(){ //全选
for(var i=0;i<ocheck.length;i++){
ocheck[i].checked = true;
}
};
obtn2.onclick = function(){ //不选
for(var i=0;i<ocheck.length;i++){
ocheck[i].checked = false;
}
};
obtn3.onclick = function(){ //反选
for(var i=0;i<ocheck.length;i++){
ocheck[i].checked = !ocheck[i].checked;
}
};
}
</script>
</head>
<body>
<input type="button" id="btn1" value="全选" />
<input type="button" id="btn2" value="不选" />
<input type="button" id="btn3" value="反选" />
<div id="div1">
<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 />
<input type="checkbox" /><br />
<input type="checkbox" /><br />
</div>
</body>
</html>
追问
能把我上面的程序做出来吗 亲
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询