<td width=" 82% "colspan=" 3 ",
< Input type= "checkbox" id= "All" > select all
<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