Implementation Code of jQuery operation input type = checkbox

Source: Internet
Author: User

Copy codeThe Code is as follows:
<Input type = "checkbox">:
The international team that qualify for the 2012 European Cup "death group" is: <br>
<Input type = "checkbox" name = "nation" value = "Germany"> Germany
<Input type = "checkbox" name = "nation" value = "Denmark"> Denmark
<Input type = "checkbox" name = "nation" value = "Holland"> Netherlands
<Input type = "checkbox" name = "nation" value = "Portugal"> Portugal

1. The first and second place in the group can only be selected.
Copy codeThe Code is as follows:
Var len = $ ("input [name = 'nation']: checked"). length;
If (len = 0 ){
Alert ("select the qualifying National Team! ");
Return false;
} Else if (len <2 ){
Alert ("select two national teams! ");
Return false;
} Else if (len> 2 ){
Alert ("Only two national teams can be selected! ");
Return false;
} Else {
Return true;
}

2. Traverse selected national teams.
Copy codeThe Code is as follows:
$ ("Input [name = 'nation']: checked"). each (function (){
Alert ("selected national team:" + $ (this). val ());
});

3. Cancel all selected national teams.
Copy codeThe Code is as follows: $ ("input [name = 'nation']: checked"). attr ("checked", false );
4. Select two national teams.
Copy codeThe Code is as follows:
$ ("Input [name = 'nation'] [value = 'Germany ']"). attr ("checked", true );
$ ("Input [name = 'nation'] [value = 'holand']"). attr ("checked", true );

5. You are not allowed to select the National Team.
Copy codeThe Code is as follows: $ ("input [name = 'nation']"). attr ("disabled", true );
6. Select the National Team.
Copy codeThe Code is as follows: $ ("input [name = 'nation']"). attr ("disabled", false );
7. Select the national team with an even or odd number of indexes (the index starts from 0 ).
Copy codeThe Code is as follows: // select the national team with an even Index
$ ("Input [name = 'nation']: even"). attr ("checked", true );
// Select the national team with an odd Index
$ ("Input [name = 'nation']: odd"). attr ("checked", true );

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.