1. Of course we need to introduce the jquery file.
2. Create a function
Var check_all = function (obj, name) {$ (": checkbox [name = '" + name + "']"). attr ("checked", obj. checked );}
3. Use
Copy codeThe Code is as follows: <! DOCTYPE Html>
<Html>
<Head>
<Script type = "text/javascript" src = "http://code.jquery.com/jquery-1.4.4.min.js"> </script>
<Script type = "text/javascript">
Function selectAll (checkbox ){
$ ('Input [type = checkbox] '). attr ('checked', $ (checkbox). attr ('checked '));
}
</Script>
</Head>
<Body>
<Input type = "checkbox" onclick = "selectAll (this);"/> select all <br/>
<Input type = "checkbox"/> <br/>
<Input type = "checkbox"/> <br/>
<Input type = "checkbox"/> <br/>
<Input type = "checkbox"/> <br/>
<Input type = "checkbox"/> <br/>
<Input type = "checkbox"/> <br/>
......
</Body>
</Html>
Select and cancel multiple groups of JQUERYCopy codeThe Code is as follows: <Script type = "text/javascript" src = "http://code.jquery.com/jquery-1.4.4.min.js"> </script>
<Script type = "text/javascript">
Function selectGroup (checkbox, obj ){
$ ('Input [name = '+ obj +'] '). attr ('checked', $ (checkbox). attr ('checked '));
}
</Script>
</Head>
<Body>
<Input type = "checkbox" onclick = "selectGroup (this, 'grp1');"/> select GROUPA <br/>
GROUPA: <br/>
<Input type = "checkbox" name = "grp1"/> 11 <br/>
<Input type = "checkbox" name = "grp1"/> 22 <br/>
<Input type = "checkbox" name = "grp1"/> 33 <br/>
<Input type = "checkbox" onclick = "selectGroup (this, 'grp2 ');"/> select GROUPB <br/>
GROUPB: <br/>
<Input type = "checkbox" name = "grp2"/> 44 <br/>
<Input type = "checkbox" name = "grp2"/> 55 <br/>
<Input type = "checkbox" name = "grp2"/> 66 <br/>
</Body>
</Html>
Additional code:
Reference Jquery library jquery-1.4.1-vsdoc.js, etc.
Jquery script code ----------------------Copy codeThe Code is as follows: $ (function (){
$ ('# Inputcheck'). click (function (){
$ ("Input [name = 'checkbox1']"). attr ("checked", $ (this). attr ("checked "));
});
}); // Select all
$ (Function (){
$ ("# Select_reverse"). click (function (){
$ ("Input [name = 'checkbox1']"). each (function (idx, item ){
$ (Item). attr ("checked ",! $ (Item). attr ("checked "));
})
});
}); // Reselect
Html front-end code ------------------------
[Code]
<Input id = "inputCheck" type = "checkbox"/> select all
<Input id = "select_reverse" type = "checkbox"/> invert Selection
<Input name = "Checkbox1" type = "checkbox"/>
<Input name = "Checkbox1" type = "checkbox"/>
<Input name = "Checkbox1" type = "checkbox"/>
<Input name = "Checkbox1" type = "checkbox"/>
<Input name = "Checkbox1" type = "checkbox"/>
<Input name = "Checkbox1" type = "checkbox"/>
[Html]