首页 > 其他 > 详细

4.1邮箱的全选,全不选,反选

时间:2018-03-04 17:48:36      阅读:172      评论:0      收藏:0      [点我收藏+]

事件:onclick

属性:checked

对于分清getElementsByTagName(‘元素名‘)里的元素名,

可以先提取其外面一层的元素,再在此基础上用getElementsByTagName(‘元素名‘)

用到for语句,if语句,length

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Examples</title>
<meta name="description" content="">
<meta name="keywords" content="">

<link href="css1.css" rel="stylesheet" type="text/css"
charset="UTF-8">
</head>
<body>
<input id="btn1" type="button" value="全选"/>
<input id="btn2" type="button" value="不选"/>
<input id="btn3" type="button" 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/>
</div>
<script src="js1.js"> </script>
</body>
</html>

///////////////////////js

window.onload=function(){
var oBtn1=document.getElementById("btn1");
var oBtn2=document.getElementById("btn2");
var oBtn3=document.getElementById("btn3");
var oDiv=document.getElementById("div1");
var aCh=oDiv.getElementsByTagName("input");
oBtn1.onclick=function(){
for(var i=0;i<aCh.length;i++){
aCh[i].checked=true;
}

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

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

4.1邮箱的全选,全不选,反选

原文:https://www.cnblogs.com/luxiaoli/p/8505243.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!