The checkbox control has its own unique attributes in the html page. It indicates the check box, so we need to select all. Next I will introduce the method for selecting all the checkbox parameters, for more information, see.
In jquery, we need to determine whether checkbox is selected. We can directly use if ($ ("# id"). attr ("checked") = true)
.
Then, if we want to implement multiple checkbox selection, we can use each for traversal.
Jquery code
The Code is as follows: |
Copy code |
Function selectall (){ Var arrChk = $ ("input [name = 'deleteid']"); // checkbox name $ (ArrChk). each (function (){ This. checked =! This. checked; }); } /// $ ("[Name = 'deleteid']"). attr ("checked", 'true'); // select all |
Instance
The Code is as follows: |
Copy code |
<A href = "javascript:;" id = "all"> select all </a> <br> <A href = "javascript:;" id = "delAll"> deselect </a> <br> <A href = "javascript:;" id = "antiAll"> reverse selection </a> <P> <input type = "checkbox" name = "checkbox1"> <Input type = "checkbox" name = "checkbox1"> B
<Input type = "checkbox" name = "checkbox1"> C </p> <P> <input type = "checkbox" name = "checkbox1"> D <Input type = "checkbox" name = "checkbox1"> E <Input type = "checkbox" name = "checkbox1"> F </p> <Script> // Select all $ ("# All"). click (function (){ $ ("Input [name = 'checkbox1']"). each (function (){ $ (This). attr ("checked", true ); }); }); // Cancel the selection $ ("# DelAll"). click (function (){ $ ("Input [name = 'checkbox1']"). each (function (){ $ (This). attr ("checked", false ); }); }); </Script> |