This article shares a piece of jQuery-based code for Selecting All check boxes, deselected all, And deselected functions. If you have any need, you can refer to jquery's functions such as selecting all, deselected, and deselected all, the following is an example. Set the following check boxes and related buttons on the page (select all, select inverse, do not select all ):
AppleOrangeBananasGrape
The complete code for implementing the relevant functions is as follows:
$ (Function () {$ ('# btn1 '). click (function () {// select all $ ("[name = 'fruit']"). attr ('checked', 'true') ;}); $ ('# btn2 '). click (function () {// do not select all $ ("[name = 'fruit']"). removeAttr ('checked') ;}; $ ('# btn3 '). click (function () {// invert $ ("[name = 'fruit']"). each (function () {if ($ (this ). attr ('checked') {$ (this ). removeAttr ('checked');} else {$ (this ). attr ('checked', 'true') ;}}); $ ("# btn4 "). click (function () {// select all odd numbers $ ("[name = 'fruit']: even "). attr ('checked', 'true');}) $ ("# btn5 "). click (function () {// obtain the values of all selected options var checkVal = ''; $ (" [name = 'fruit'] [checked] "). each (function () {checkVal + = $ (this ). val () + ',';}) alert (checkVal );})});
Before using jquery, you must introduce the jquery package!
The above is the Code Compiled by xiaobian. It is very convenient to use and I hope it can help you.
For more information about jquery-based functions such as checkbox selection, deselection, and deselection, refer to PHP!