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>
<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高级应用
- php入门学习知识点八 PHP中for循环基本应用之九九乘法口绝表
- C# 3循环 for语句应用
- Java (for循环综合应用)
- Java (for循环基础应用)
- PHP学习第一节----for循环的应用及对date函数的初步使用
- for循环语句示例应用
- 【学习ios之路:C语言】for ,while,do while循环的应用
- 黑马程序员:while与for循环的应用
- JAVA进阶之旅(一)——增强for循环,基本数据类型的自动拆箱与装箱,享元设计模式,枚举的概述,枚举的应用,枚举的构造方法,枚举的抽象方法
- for循环的巧妙应用
- shell for循环与数组应用介绍
- java知识:增强for循环应用汇总
- for循环的应用
- java新特性之for循环的增强应用
- javaSE----for,wile ,do while循环的应用
- DOS编程:FOR循环及在查看局域网所有IP的应用
- 二层for循环的应用系列之一:数字升序排列及其类似应用
- 2015/7/16/for循环的应用
- JAVA进阶之旅(一)——增强for循环,基本数据类型的自动拆箱与装箱,享元设计模式,枚举的概述,枚举的应用,枚举的构造方法,枚举的抽象方法