javascript

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<script>
window.onload =function()
{
 var a1 = document.getElementById('btn1');
  var a2 = document.getElementById('btn2');
   var a3 = document.getElementById('btn3');
 //选 div1以下东西
 
 var oDiv =document.getElementById('div1');
 var aCh = oDiv.getElementsByTagName('input');
 
 a1.onclick =function()
 {
for(i = 0;i<aCh.length;i++)
{
 aCh[i].checked =true;
}

 };
 
  a2.onclick =function()
 {
for(i = 0;i<aCh.length;i++)
{
 aCh[i].checked =false;
}

 };
 
  a3.onclick =function()
 {
for(i = 0;i<aCh.length;i++)
{
if( aCh[i].checked ==false)
{
 aCh[i].checked =true;
}else{
aCh[i].checked = false;
}
 
 
}

 };
 
}
</script>
</head>


<body>
<input id="btn1" type="button" value="全选"/><br/>
<input id="btn2" type="button" value="不选"/><br/>
<input id="btn3" type="button" value="反选"/><br/>
<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/>
<input type="checkbox"/><br/>
<input type="checkbox"/><br/>
</div>
</body>
</html>
原文地址:https://www.cnblogs.com/blfbuaa/p/6932197.html