您的位置:首页 > 其它

for循环的应用(以163邮箱为例)(全选或不选或反选)

2016-12-08 23:42 155 查看
<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
window.onload=function(){

var oDiv1=document.getElementById("div1");
var oBtn1=document.getElementById("btn1");
var oBtn2=document.getElementById("btn2");
var oBtn3=document.getElementById("btn3");
var aBox=oDiv1.getElementsByTagName("input");

oBtn1.onclick=function(){

for(var i=0;i<aBox.length;i++){
aBox[i].checked=true;
}

}
oBtn2.onclick=function(){

for(var i=0;i<aBox.length;i++){
aBox[i].checked=false;
}

}

oBtn3.onclick=function(){

for(var i=0;i<aBox.length;i++){

if(aBox[i].checked==true){

aBox[i].checked=false;

}else{

aBox[i].checked=true;

}

}

}

/*oBtn3.onclick=function(){

for(var i=0;i<aBox.length;i++){

aBox[i].checked=!aBox[i].checked;

}

}*/

}
</script>
</head>
<body>

<input type="button" name="" id="btn1" value="全选"
/>
<input type="button" name="" id="btn2" value="全不选" />
<input type="button" name="" id="btn3" value="反选" />
<br/>
<div id="div1">

<input type="checkbox" name="" id="" value="" />11<br/>
<input type="checkbox" name="" id="" value="" />22<br/>
<input type="checkbox" name="" id="" value="" />33<br/>
<input type="checkbox" name="" id="" value="" />55<br/>
<input type="checkbox" name="" id="" value="" />66<br/>
<input type="checkbox" name="" id="" value="" />77<br/>

</div>

</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  for循环