返回全选 不选 返......登陆

全选 不选 返选

土豆烧牛肉2019-03-27 17:48:04177

<!DOCTYPE html>

<html>

 <head>

  <meta charset="UTF-8">

  <title> New Document </title>  

 </head>

 <body>

  

<!--<script>

var body = document.getElementById("body");

var childs = body.childNodes;

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

console.log(childs[i].nodeType);

 console.log(childs[i].nodeName);

  console.log(childs[i].nodeValue);

}

</script>-->


<div id="d1">

<input type="checkbox" name="class[]"/>语文

<input type="checkbox" name="class[]"/>数学

<input type="checkbox" name="class[]"/>英语

<input type="checkbox" name="class[]"/>政治


<br/>

<input type="checkbox" name="class[]"/>语文

<input type="checkbox" name="class[]"/>数学

<input type="checkbox" name="class[]"/>英语

<input type="checkbox" name="class[]"/>政治

<br/>

<input type="button" value="全选" id="all"/>

<input type="button" value="不选" id="none"/>

<input type="button" value="返选" id="prev"/>

</div>

<script>

var d1=document.getElementById("d1");

var childs=d1.childNodes;

var all=document.getElementById("all");

var none=document.getElementById("none");

var prev=document.getElementById("prev");



all.onclick=function(){

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


if(childs[i].nodeName=="INPUT"&&childs[i].type=="checkbox"){


childs[i].checked=true;

}


}


}

all.onclick=function(){

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


if(childs[i].nodeName == "INPUT"&&childs[i].type == "checkbox"){


childs[i].checked=false;


}


}


}

prev.onclick=function(){


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


id(childs[i].nodeName=="INPUT" && childs[i].type=="checkbox"){


if(childs[i].checked==true){childs[i].checked=false;


}else{

childs[i].checked=true;

}

}

}

}




</script>

 </body>

</html>


最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送