In jquery we have to determine if the checkbox is selected we can use if ($ ("#id") directly. attr ("checked") ==true)
to operate.
So if we're going to implement multiple checkbox selections, we can iterate through each
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" >a <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 Selection $ ("#delAll"). Click (function () { $ ("Input[name= ' CheckBox1 ']"). each (function () { $ (this). attr ("checked", false); }); }); </script> |