Select All js check boxes and select all code for jquery check boxes

Source: Internet
Author: User

Select All js check boxes and select all code for jquery check boxes

Select all the check boxes for webpage special effects and select all the code for the jquery check boxes.
<! -- Now that I only provide code for Selecting All and deselected webpage special effects check boxes, today we provide two js checkbox full selection and jquery check box full selection. You can take a look below. -->
<Script>
// Not in form:

Function checkall ()
{
Arr = new array ("aa", "bb", "cc", "dd ");
For (var I = 0; I <arr. length; I ++)
{
Var e = arr [I];
Eval (document. getelementbyid (e). checked = (document. getelementbyid (e). checked! = True? True: false );
}
}


Function checkall (form) // pass a form as a parameter
{
For (var I = 0; I <form. elements. length; I ++) // loops the elements in this form.
{
Var e = form. elements [I]; // one-by-one element judgment
If (e. name! = "Chkall" & e. disabled! = True) // if the name attribute of this element is chkall and disabled! = True. That is, when the control is available.
E. checked = form. chkall. checked; // The checked of the control element is consistent with the checked of the selected control.
}
}


// Code of the check box for Selecting All juqery checkbox

$ (Document). ready (function (){
// Define the name of the all-selected box as $ chkall
Var $ chkall = $ ('# checkedall ');
Var $ chkarry = $ ('input [type = "checkbox"] '). not ($ (' # checkedall '); // obtain the check boxes except the all check boxes.
// The implementation function of the all-selected box
$ Chkall. click (function (){
Var B = $ (this). attr ('checked'); // obtain the value of the all-selected box.
$ Chkarry. each (function () {$ (this ). attr ('checked', B) ;}); // You can synchronize the values of other check boxes with the Select All option to select all or cancel the Select All option.
});
// Check boxes except all
$ Chkarry. each (function (){
$ (This). click (function (){
// First assign the value of each other check box to the entire selection box
$ Chkall. attr ('checked', $ (this). attr ('checked '));
// Check whether all other check boxes have been selected for recycling. If all the check boxes are selected, the system will synchronize them.
// If all other check items have been selected, select both.
$ Chkarry. each (function (index) {$ chkall. attr ('checked', ($ chkall. attr ('checked') & $ chkarry. eq (index ). attr ('checked '))? True: false );});
});
});
});


</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.