Copy Code code as follows:
<input type= "checkbox":
The 2012 European Cup "Group of Death" 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" > Holland
<input type= "checkbox" Name= "Nation" value= "Portugal" > Portugal
1, the group's first and second qualified, so the limit can only select two.
Copy Code code as follows:
var len = $ ("Input[name= ' Nation ']:checked"). Length;
if (len==0) {
Alert ("Please select the national team to qualify!") ");
return false;
}else if (len<2) {
Alert ("Please select two national teams!") ");
return false;
}else if (len>2) {
Alert ("Only two national teams can be selected!") ");
return false;
}else {
return true;
}
2, traversing the selected national team.
Copy Code code as follows:
$ ("Input[name= ' Nation ']:checked"). each (function () {
Alert ("Selected national team:" +$ (This). Val ());
});
3, cancellation of all selected national team.
Copy Code code as follows:
$ ("Input[name= ' Nation ']:checked"). attr ("checked", false);
4, designated selected two national team.
Copy Code code as follows:
$ ("Input[name= ' Nation '][value= ' Germany ')"). attr ("Checked", true);
$ ("Input[name= ' Nation '][value= ' Holland ')"). attr ("Checked", true);
5. It is forbidden to choose national team.
Copy Code code as follows:
$ ("Input[name= ' Nation ']"). attr ("Disabled", true);
6. Allow to choose National team.
Copy Code code as follows:
$ ("Input[name= ' Nation ']"). attr ("disabled", false);
7, select the index is even or odd number of national teams (index is starting from 0).
Copy Code code as follows:
$ ("Input[name= ' Nation ']:even"). attr ("Checked", true);
//Select the index for Odd national team
$ ("Input[name= ' Nation ']:odd"). attr ("Checked", true);