Jquery --- Select All or cancel all of the checkbox

Source: Internet
Author: User

Jquery --- Select All or cancel all of the checkbox

Checkbox is an inevitable control in system development. Generally, multiple checkboxes are selected, all are selected, or all are canceled. Some time ago, I encountered the checkbox usage. A few days later, I would like to give some help to my friends who want to use the checkbox control.

Sometimes we need to click a checkbox control. When it is selected, all other checkboxes are selected, and then click it to deselect it. All other checkboxes are deselected. At this time, we can use the following code in the HTML or. jsp file to implement this function. The Code is as follows:

 

   Select All  
$(document).ready(function(){        $(#checkAll).click(function(){            if(this.checked)            {                $(input[name='checkbox']).each(function(){                    this.checked=true;                });                // $([name='checkbox']).attr(checked,'true');            }            else            {                $(input[name='checkbox']).each(function(){                    this.checked=false;                });                //$([name='checkbox']).attr(checked,'false');            }        });    });
If the check box checkbox is selected, How can I obtain the checkbook value of the selected check box?

 

 

 0 1 2 3 4 5 6 7  

 

 

Function jqchk () {// jquery obtains the check box value var chk_value = []; $ (input [name = test]: checked ). each (function () {chk_value.push ($ (this ). val () ;}); alert (chk_value.length = 0? 'You have not selected any content! ': Chk_value );}
The above are several common functions of the checkbox, hoping to help our friends.


 

 

 

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.