JavaScript implementation Click Select all, again click Cancel Select All

Source: Internet
Author: User

The following are the implementation ideas, have been tested, for reference

var allset = document.getElementById (' Allset '); Get the Select All button element

var a = allset.custom; Custom properties for the Select All button

a = 0; Custom attribute value is 0

var input1 = all.getelementsbytagname (' input '); Get all the input tags under all;

Add Click events to the Select All button to make judgments;

Allset. onclick = function () {

If A is 0, the first for loop is executed;

if (a = = 0) {

Loops through all input tags;

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

Leave the input label selected (checked = true selected), (checked = False unchecked );

input1[i].checked = true;

The value of the custom property is changed here to 1

a = 1

}

}

// If a for 1 executes the next for loop, leave the input label unchecked

else{

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

input1[i].checked = false;

A = 0

}

}

}

JavaScript implementation Click Select all, again click Cancel Select All

Related Article

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.