Implementation code for jquery operation input Type=checkbox

Source: Internet
Author: User

Implementation code for jquery operation input Type=checkbox

jquery operation input Type=checkbox implementation code, the need for friends can refer to, this side of the script home recommend you look at our previous published articles

Copy CodeThe code is as follows:
<input type= "checkbox";:
The 2012 European Cup "death group" team 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 team to qualify, so to limit only two items to be selected.

Copy CodeThe code is as follows:
var len = $ ("Input[name= ' Nation ']:checked"). Length;
if (len==0) {
Alert ("Please select the national team!") ");
return false;
}else if (len<2) {
Alert ("Please select two national teams!") ");
return false;
}else if (len>2) {
Alert ("Only choose two national teams!") ");
return false;
}else {
return true;
}


2. Traverse the selected national team.

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, the designated two national teams selected.

Copy CodeThe code is as follows:
$ ("Input[name= ' Nation '][value= ' Germany ']"). attr ("Checked", true);
$ ("Input[name= ' Nation '][value= ' Holland ']"). attr ("Checked", true);


5. Prohibit the selection of national team.

Copy CodeThe code is as follows: $ ("Input[name= ' Nation ')"). attr ("Disabled", true);


6. Allow the selection of national teams.

Copy CodeThe code is as follows: $ ("Input[name= ' Nation ')"). attr ("disabled", false);


7. Select the national team with an even or odd index (the index is starting from 0).

Copy CodeThe code is as follows:

Select the national team with an even number of indexes
$ ("Input[name= ' Nation ']:even"). attr ("Checked", true);
Select the national team with the odd index
$ ("Input[name= ' Nation ']:odd"). attr ("Checked", true);

Implementation code for jquery operation input Type=checkbox

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.