[JQuery] Select All and invert check boxes to determine which check boxes are selected. jquery Selects all check boxes.

Source: Internet
Author: User

[JQuery] Select All and invert check boxes to determine which check boxes are selected. jquery Selects all check boxes.

This article selects and deselected all the check boxes in [JavaScript] to determine which check boxes are selected (click to open the link) as a companion article, and implements the content again in the jQuery framework, the following results are also achieved:


The layout is the same, because in the jQuery framework, you do not need to specify a specific onclick event handler for the button. You can directly use jQuery to specify the layout:

<! Doctype html public "-// W3C // dtd html 4.01 // EN" "http://www.w3.org/TR/html4/strict.dtd"> Then in jQuery, take the check box array whose name is checkBoxGroup, And you can directly write $ (": checkbox [name = 'checkboxgroup']"), of course, $ ("input [type = 'checkbox'] [name = 'checkboxgroup']") is fine, but $ (": checkbox [name = 'checkboxgroup']") the code is simpler. Pay attention to the colon Before the checkbox. The same as the document. getElementsByName ("xx") of Javascript, the same-digit check box array. Only in jQuery, you can directly use each to traverse. Set whether to use prop for the check box and do not use attr. For details, see [jQuery] attr and prop for the check box operation (click to open the link.

<Script type = "text/javascript"> // Where is the check box selected? $ ("# Selected "). click (function () {var str = "selected check box:"; $ (": checkbox [name = 'checkboxgroup']: checked "). each (function () {str + = $ (this ). val () + "," ;}); alert (str) ;}); // select all $ ("# selectAll "). click (function () {$ (": checkbox [name = 'checkboxgroup']"). each (function () {$ (this ). prop ("checked", true) ;}); // reselect $ ("# selectReserve "). click (function () {$ (": checkbox [name = 'checkboxgroup']"). each (function () {$ (this ). prop ("checked ",! $ (This). prop ("checked") ;};}); </script>


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.