Dowemo
0 0 0 0

We often see that there will be a selection of options where you need options, and when we click select all, all of them are selected, and let's see how to implement this.
Start with the idea: want to use js to write the select all button, first we want to get all the select buttons and other selection buttons, then give the select.

<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><title>Title</title></head><body><inputtype="checkbox"id="btn"><divid="box"><inputtype="checkbox"><inputtype="checkbox"><inputtype="checkbox"><inputtype="checkbox"></div></body></html><script> window.onload=function() {//1、获取全选按钮var oBtn=document.getElementById("btn");//2、获取box中的所有inputvar oBox=document.getElementById("box");
 var inputs=oBox.getElementsByTagName("input");//3、当点击全选按钮的时候所有的input被选中//3、1 给全选按钮添加点击事件 oBtn.onclick=function() {//3、2 遍历box中的所有inputfor(var i=0;i<inputs.length;i++){
 inputs[i].checkd=true;
 }
 }
 }</script>

Invert, as the name suggests, isn't selected when clicked on the invert button, the selected selection box is selected, and the selected selection box is selected

<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><title>Title</title></head><body><inputtype="checkbox"id="btn"><divid="box"><inputtype="checkbox"><inputtype="checkbox"><inputtype="checkbox"><inputtype="checkbox"></div></body></html><script> window.onload=function() {//1.获取反选按钮var oBtn=document.getElementById("btn");//2.获取box中的所以inputvar oBox=document.getElementById("box");
 var inputs=oBox.getElementsByTagName("input");//3.给反选按钮添加点击事件 oBtn.onclick=function() { oBtn.checked=true;
 for(var i=0;i<inputs.length;i++){//3.1 遍历判断有哪些input的checked的值为false;if(inputs[i].checked==false){//3.2 给筛选出来的input的checked的值为true; inputs[i].checked=true;
 }else {//3.3 给其他的赋值为false; inputs[i].checked=false;
 }
 }
 }
 }</script>



Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs