Jquery select all in one sentence/cancel all selections

Source: Internet
Author: User

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]

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.