Home > Web Front-end > JS Tutorial > jQuery operation input type=checkbox implementation code_jquery

jQuery operation input type=checkbox implementation code_jquery

WBOY
Release: 2016-05-16 17:52:56
Original
1105 people have browsed it
Copy code The code is as follows:

:
2012 The national teams that qualified in the "Group of Death" of the European Cup are:

Germany
Denmark
Netherlands
Portugal

 1. The first and second place in the group qualify, so they are restricted to only two choices.
Copy code The code is as follows:

var len = $("input[name='nation ']:checked").length;
if(len==0) {
alert("Please select the qualifying national team!");
return false;
}else if(len< ;2) {
alert("Please select two national teams!");
return false;
}else if(len>2) {
alert("Only two countries can be selected Team! ");
return false;
}else {
return true;
}

 2. Traverse the selected national teams.
Copy code The code is as follows:

$("input[name='nation']: checked").each(function(){
alert("Selected national team: " $(this).val());
});

 3. Deselect all selected national teams.
Copy code The code is as follows:
$("input[name='nation']:checked") .attr("checked",false);

 4. Specify two national teams.
Copy code The code is as follows:

$("input[name='nation'][ value='Germany']").attr("checked",true);
$("input[name='nation'][value='Holland']").attr("checked",true) ;

 5. It is forbidden to select the national team.
Copy code The code is as follows:
$("input[name='nation']").attr ("disabled",true);

 6. Allow selection of the national team.
Copy code The code is as follows:
$("input[name='nation']").attr ("disabled",false);

7. Select the national team whose index is even or odd (the index starts from 0).
Copy code The code is as follows:
//Select the national team with an even number
$(" input[name='nation']:even").attr("checked",true);
//Select the national team with an odd index
$("input[name='nation']:odd ").attr("checked",true);
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template