<input type= "checkbox";:
12345 |
2012欧洲杯"死亡之组"小组出线的国家队是:< br > < input type="checkbox" name="nation" value="Germany">德国 < input type="checkbox" name="nation" value="Denmark">丹麦 < input type="checkbox" name="nation" value="Holland">荷兰 < input type="checkbox" name="nation" value="Portugal">葡萄牙 |
1, the first and second team to qualify, so to limit only two items to be selected.
12345678910111213 |
var
len = $(
"input[name=‘nation‘]:checked"
).length;
if
(len==0) {
alert(
"请选择出线的国家队!"
);
return
false
;
}
else
if
(len<2) {
alert(
"请选择两个国家队!"
);
return
false
;
}
else
if
(len>2) {
alert(
"只能选择两个国家队!"
);
return
false
;
}
else
{
return
true
;
}
|
2. Traverse the selected national team.
123 |
$( "input[name=‘nation‘]:checked" ).each( function (){ alert( "已选择的国家队: " +$( this ).val()); }); |
3. Cancel all selected national teams.
1 |
$( "input[name=‘nation‘]:checked" ).attr( "checked" , false ); |
4, the designated two national teams selected.
12 |
$( "input[name=‘nation‘][value=‘Germany‘]" ).attr( "checked" , true ); $( "input[name=‘nation‘][value=‘Holland‘]" ).attr( "checked" , true ); |
5. Prohibit the selection of national team.
1 |
$( "input[name=‘nation‘]" ).attr( "disabled" , true ); |
6. Allow the selection of national teams.
1 |
$( "input[name=‘nation‘]" ).attr( "disabled" , false ); |
7. Select the national team with an even or odd index (the index is starting from 0).
1234 |
//选中索引为偶数的国家队 $( "input[name=‘nation‘]:even" ).attr( "checked" , true ); //选中索引为奇数的国家队 $( "input[name=‘nation‘]:odd" ).attr( "checked" , true ); |
jquery operation <input type= "checkbox";