jquery One sentence Select all/Cancel all select _jquery

Source: Internet
Author: User
Tags jquery library
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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.