JS implements the CheckBox check box function of Selecting All, not selecting, or not selecting all. jscheckbox

Source: Internet
Author: User

JS implements the CheckBox check box function of Selecting All, not selecting, or not selecting all. jscheckbox

The CheckBox control indicates whether a specific status (that is, the option) is selected (on, the value is 1) or cleared (off, the value is 0 ). Use this control in applications to provide users with "True/False" or "yes/no" options. Because checkboxes work independently, you can select any number of checkboxes at the same time for Option combinations.

The CheckBox check box JS implements the function of Selecting All, not selecting all, and not selecting all. The details are as follows:

Ideas:

  • 1. Get Elements
  • 2. Select none for all and add click events
  • 3. Use for loop checkbox
  • 4. Set the checked of the checkbox to true to achieve full selection.
  • 5. Set the checked of the checkbox to false, so that the checkbox is not selected.
  • 6. if it is determined by the if statement, if checked is selected as true, the checked state is set to false, and if checked is set to false, the checked state is set to true.

Html code:

<Input type = "button" value = "select all" id = "sele"/> <input type = "button" value = "do not select" id = "setinterval"/> <input type = "button" value = "invert" id = "clear"/> <div id = "checkboxs"> <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>

Js Code:

<Script> window. onload = function () {var sele = document. getElementById ('sele'); // obtain all var unsele = document. getElementById ('setinterval'); // get var clear = document not selected. getElementById ('clear'); // obtain var checkbox = document. getElementById ('checkboxs '); // obtain divvar checked = checkbox. getElementsByTagName ('input'); // obtain the input in the div // select all sele. onclick = function () {for (I = 0; I <checked. length; I ++) {checked [I]. checked = true} // unsele is not selected. onclick = function () {for (I = 0; I <checked. length; I ++) {checked [I]. checked = false }}// deselect clear. onclick = function () {for (I = 0; I <checked. length; I ++) {if (checked [I]. checked = true) {checked [I]. checked = false} else {checked [I]. checked = true }}</script>

The above is all the content of this article. I hope you will like it.

Articles you may be interested in:
  • Js checkbox usage highlights
  • Javascript: Set the checkbox check box in a DIV Area
  • How to dynamically Add a Checkbox instance in Js
  • Extjs 4.x get the value of the form CheckBox check box
  • Use javascript to obtain the checkbox check box and obtain the selected options.
  • Example of the option selected by js to obtain the checkbox check box
  • Example code of the checkbox check box implemented by javascript

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.