Select all events for jquery, and select all events for jquery.

Source: Internet
Author: User

Select all events for jquery, and select all events for jquery.


& Lt; td width = "82%" colspan = "3" & gt;
<Input type = "checkbox" id = "all"> select all & nbsp;
<Input type = "checkbox" id = "reverse"> invert Selection
</Td>
& Lt; td width = "82%" colspan = "3" & gt;
<S: checkboxlist name = "resUuids" list = "resList" listKey = "uuid" listValue = "name"> </s: checkboxlist>
</Td>

 

 

$ (Function (){
// Select all
$ ("# All"). click (function (){
// Select all the following components
// $ ("[Name = resUuids]") is a multi-component with an array of objects.
// $ ("[Name = resUuids]"). attr ("checked", "checked ");

// Obtain the status of the current component first
// $ (This). attr ("checked ")
// Set all components to the corresponding status
// $ ("[Name = resUuids]"). attr ("checked", $ (this). attr ("checked "));

// $ (This). attr ("checked") What is the obtained value?
// Alert ($ (this). attr ("checked"); // undefined
// $ ("[Name = resUuids]"). attr ("checked", "undefined ");

// Js syntax rule. All values except false, FALSE, "false", "FALSE", and 0 are considered as true.
// $ ("[Name = resUuids]"). attr ("checked", false );

Var flag = $ (this). attr ("checked ");
$ ("[Name = resUuids]"). attr ("checked", flag = "checked ");
});

 

// Invert Selection
$ ("# Reverse"). click (function (){
// Switch the status of all components to the reverse status of the original status

// $ ("[Name = resUuids]"). attr ("checked ",! ($ ("[Name = resUuids]"). attr ("checked") = "checked "));

// When the selector selects multiple components, operations are performed on the first component to obtain any data of the component.
// Alert (! ($ ("[Name = resUuids]"). attr ("checked") = "checked "));

// Iterate each component so that its operation status is reversed for the original status of the corresponding component
$ ("[Name = resUuids]"). each (function (){
// Use the each operation to perform operations on each component
Var flag = $ (this). attr ("checked ");
$ (This). attr ("checked ",! (Flag = "checked "));
});
CheckSelect ();
});

 

// Bind the component
$ ("[Name = resUuids]"). click (function (){
// Set the all-selected status to the overall status value of all components.
CheckSelect ();
});

Function checkSelect (){
Var allFlag = true;
$ ("[Name = resUuids]"). each (function (){
Var flag = $ (this). attr ("checked") = "checked ";
// &: Bit operation and &: logical and
AllFlag = allFlag & flag;
});
$ ("# All"). attr ("checked", allFlag );
}

});

 

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.