JQuery operation <input type = "checkbox">, jquerycheckbox
<Input type = "checkbox">:
12345 |
The National 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.
12345678910111213 |
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.
123 |
$( "input[name='nation']:checked" ).each( function (){ alert( "Selected national team :" +$( this ).val()); }); |
3. Cancel all selected national teams.
1 |
$( "input[name='nation']:checked" ).attr( "checked" , false ); |
4. Select two national teams.
12 |
$( "input[name='nation'][value='Germany']" ).attr( "checked" , true ); $( "input[name='nation'][value='Holland']" ).attr( "checked" , true ); |
5. You are not allowed to select the National Team.
1 |
$( "input[name='nation']" ).attr( "disabled" , true ); |
6. Select the National Team.
1 |
$( "input[name='nation']" ).attr( "disabled" , false ); |
7. Select the national team with an even or odd number of indexes (the index starts from 0 ).
1234 |
// 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 ); |