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