When we use js to implement web operations, full selection, no selection, and invert selection of multiple selection boxes are the most common functions, this batch operation is especially required when there is a large amount of data to bring convenient and quick services to users.
In the following example, jquery is used to implement the function of Selecting All, not selecting all, And deselection for the checkbox multiple selection box:
Suppose there are four multiple checkbox boxes, they are included in a div with ID = "Chk, the IDS of all selected, unselected, and unselected buttons are btnallchk, btnallnotchk, and btninvert.
The Code is as follows:
$ (Function () {// do not select all $ ("# btnallnotchk "). click (function () {$ ("# chk input: checkbox "). removeattr ("checked") ;}); // select $ ("# btnallchk "). click (function () {$ ("# chk input: checkbox "). ATTR ("checked", "checked") ;}); // reselect $ ("# btninvert "). click (function () {// 1. method 1: Implement invert selection $ ("# chk input: checkbox "). each (function () {This. checked =! This. checked;}) // 2. method 2: Implement invert selection // $ ("# chk input: checkbox "). each (function () {// if ($ (this ). ATTR ("checked") {// $ (this ). ATTR ("checked", false); // else {// $ (this ). ATTR ("checked", "checked"); //}) // 3. method 3: Implement invert selection // var $ CKS =$ ("# chk input: checkbox"); // For (VAR I = 0; I <$ cks. length; I ++) {// $ cks. get (I ). checked =! $ Cks. Get (I). Checked ;//}});})
In this way, we can select, reselect, and unselect all checkpoints.
Note: 1. jquery itself is formed by the accumulation of JavaScript code;
2. Import the jquery control before using the jquery statement.