jquery to write a checkbox--similar to the full selection of mailbox features _jquery

Source: Internet
Author: User
Tags jquery library
Previously used in the original JS written checkbox--similar to the full choice of mailbox features, click here. Recently in learning jquery, today I took the time to write a checkbox--similar to a mailbox full selection feature in jquery.
Copy Code code as follows:

<! DOCTYPE html>
<meta charset= "UTF-8" >
<title>checkbox</title>
<body>
<input type= "checkbox" Name= "btn" id= "btn"/><label for= "BTN" > select all/All </label><br/>
<input type= "checkbox" Name= "Choose" id= "CheckBox1"/><label for= "CheckBox1" > Options 1</label><br/ >
<input type= "checkbox" Name= "Choose" id= "CheckBox2"/><label for= "CheckBox2" > Options 2</label><br/ >
<input type= "checkbox" Name= "Choose" id= "Checkbox3"/><label for= "Checkbox3" > Options 3</label><br/ >
<input type= "checkbox" Name= "Choose" id= "checkbox4"/><label for= "checkbox4" > Options 4</label><br/ >
<input type= "checkbox" Name= "Choose" id= "checkbox5"/><label for= "checkbox5" > Options 5</label><br/ >
<input type= "checkbox" Name= "Choose" id= "checkbox6"/><label for= "checkbox6" > Options 6</label><br/ >
<input type= "checkbox" Name= "Choose" id= "checkbox7"/><label for= "checkbox7" > Options 7</label><br/ >
<input type= "checkbox" Name= "Choose" id= "checkbox8"/><label for= "checkbox8" > Options 8</label><br/ >
<input type= "checkbox" Name= "Choose" id= "checkbox9"/><label for= "checkbox9" > Options 9</label><br/ >
<input type= "checkbox" Name= "Choose" id= "checkbox10"/><label for= "checkbox10" > Options 10</label><br />
<a href= "javascript:;" id= "btn2" > Anti-election </a>
</body>
<script type= "Text/javascript" src= "/js/jquery.min.js" ></script>
<script type= "Text/javascript" >
$ (function () {
var checkboxes = $ (' input[name=choose] ');
var btn = $ (' #btn ');
var btn2 = $ (' #btn2 ');
Btn.click (function () {
Checkboxes.attr (' checked ', this.checked);
});
Checkboxes.click (function () {
var flag = true;
Checkboxes.each (function () {
if (!this.checked) flag = false;
});
Btn.attr (' checked ', flag);
});
Btn2.click (function () {
var flag = true;
Checkboxes.each (function () {
this.checked =!this.checked;
if (!this.checked) flag = false;
});
Btn.attr (' checked ', flag);
});
});
</script>

Small Tips: If you use jquery, you need to introduce the jquery library.
PS: The above is I learned by the jquery knowledge, random write some effects.

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.