JS do a select all, Use a checkbox check box to make multiple checkbox check box of the Select button, when there is a check box is not selected, the checked of the All button is False

Source: Internet
Author: User

Use a checkbox check box to make the Select All button for multiple checkbox check box, when one check box is not selected, the checked of the button is false, and when all checkboxes are selected, the Select All button is also Selected.

Detailed

There are two ways to make the check box in the <input type= "checkbox"/> selected.

Method one: Add the checked property directly in the HTML rows . eg:<input type= "checkbox" checked/>

Method two: use JavaScript to make the input object checked= "true"; Eg:document.getElementsByTagName (' input ') [0].checked= ' true ';

<!DOCTYPE HTML><HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8">    <title>Select All</title><Script>window.onload= function(){    varAinput=document.getElementsByTagName ('input'); varOinput=ainput[0]; vara= 0; varb= 0; ainput[0].onclick= function(){         for (varI= 0; I<ainput.length; i++) {            if(ainput[0].checked== true) {ainput[i].checked= true; }Else{ainput[i].checked= false;    }        }    };  for (varI= 1; I<ainput.length; i++) {ainput[i].onclick= function() {a= 0; b= 0;  for (varI= 1; I<ainput.length; i++) {                if(ainput[i].checked== false) {a++; }Else{b++; }            }            if(a>0) {oinput.checked= false; }Else if(b==Ainput.length-1) {oinput.checked= true;        };    }; }};</Script></Head><Body><P><inputtype= "checkbox"name="" />Select All</P><inputtype= "checkbox"name="" /><BR/><inputtype= "checkbox"name="" /><BR/><inputtype= "checkbox"name="" /><BR/><inputtype= "checkbox"name="" /><BR/><inputtype= "checkbox"name="" /><BR/><inputtype= "checkbox"name="" /><BR/><inputtype= "checkbox"name="" /><BR/><inputtype= "checkbox"name="" /><BR/><inputtype= "checkbox"name="" /><BR/><inputtype= "checkbox"name="" /><BR/><inputtype= "checkbox"name="" /><BR/></Body></HTML>

JS do a select all, Use a checkbox check box to make multiple checkbox check box of the Select button, when there is a check box is not selected, the checked of the All button is False

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.