for循環的應用(以163郵箱爲例)(全選或不選或反選)

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
window.οnlοad=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.οnclick=function(){
for(var i=0;i<aBox.length;i++){
aBox[i].checked=true;
}
}
oBtn2.οnclick=function(){
for(var i=0;i<aBox.length;i++){
aBox[i].checked=false;
}
}

oBtn3.οnclick=function(){
for(var i=0;i<aBox.length;i++){
if(aBox[i].checked==true){
aBox[i].checked=false;
}else{
aBox[i].checked=true;
}
}
}

/*oBtn3.οnclick=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>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章