1, of course, to introduce jquery file.
2. Establish function
var check_all = function (obj,name) {$ (': Checkbox[name= ' "+name+ ']"). attr ("Checked", obj.checked);
3. Use
Copy Code code as follows:
<! DOCTYPE html>
<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>
<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>
Multiple groups of jquery selection and cancellation
Copy Code code 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>
<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/><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>
Additional code to add:
Referencing jquery library Jquery-1.4.1-vsdoc.js etc.
jquery Script code ——————————————————————
Copy Code code 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"));
})
});
});//anti-election
HTML foreground Code ————————————————————————
[Code]
<input id= "Inputcheck" type= "checkbox"/> Select all
<input id= "Select_reverse" type= "checkbox"/> Anti-election
<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]