jquery Select All All events binding

Source: Internet
Author: User

                   
<td width=" 82% "colspan=" 3 ",
< Input type= "checkbox" id= "All" > select all &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type= "checkbox" id= "reverse" > Reverse selection
</TD>
<td width=" 82% "colspan=" 3 ",
< S:checkboxlist name= "Resuuids" list= "reslist" listkey= "uuid" listvalue= "name" ></S:CHECKBOXLIST>
</TD>

$ (function () {
Select All
$ ("#all"). Click (function () {
Select all of the following components
$ ("[Name=resuuids]") is multiple components, the whole is an array of objects
$ ("[Name=resuuids]"). attr ("Checked", "checked");

Get the status of the current component first
$ (this). attr ("checked")
Set all components to their corresponding states
$ ("[Name=resuuids]"). attr ("Checked", $ (this). attr ("checked"));

$ (this). attr ("checked") gets the value exactly what
Alert ($ (this). attr ("checked")); Undefined
$ ("[Name=resuuids]"). attr ("Checked", "undefined");

JS syntax rules, except False,false, "false", "false", all values other than 05 values, are considered true
$ ("[Name=resuuids]"). attr ("checked", false);

var flag = $ (this). attr ("checked");
$ ("[Name=resuuids]"). attr ("checked", flag = = "Checked");
});

//Reverse selection
$ ("#reverse"). Click (function () {
//Switch the state of all components to the reversed state of the original state
            
//$ ("[Name=resuuids]"). attr ("Checked",! ( $ ("[Name=resuuids]"). attr ("checked") = = "Checked"));
            
//When the selector has multiple components selected, any data that gets the component is manipulated on the first component
//alert (! ( $ ("[Name=resuuids]"). attr ("checked") = = "Checked"));
            
//Iterate over each component so that its operation state is the inverse state of the original state of the corresponding component
$ ("[Name=resuuids]"). each (function () {
//Use each operation to implement actions for each component
var flag = $ (this). attr ("checked");
$ (this). attr ("Checked",! ( Flag = = "Checked"));
            });
Checkselect ();
        });

//Binding Components
$ ("[Name=resuuids]"). Click (function () {
//Set the state of the Select All to a comprehensive status value based on all components
Checkselect ();
        });
        
function Checkselect () {
var allflag = true;
$ ("[Name=resuuids]"). each (function () {
var flag = $ (this). attr ("checked") = = "Checked";
//&: bitwise operations and &&: Logic and
Allflag = Allflag && flag;
            });
$ ("#all"). attr ("Checked", allflag);
        }
        
    });

jquery Select All All events binding

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.