<input type="checkbox">: 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 place in the group qualify, so we have to limit ourselves to two choices.
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 teams.
$("input[name='nation']:checked").each(function(){ alert("已选择的国家队: "+$(this).val()); });
3. Cancel all selected national teams.
$("input[name='nation']:checked").attr("checked",false);
4. Designate two national teams.
$("input[name='nation'][value='Germany']").attr("checked",true); $("input[name='nation'][value='Holland']").attr("checked",true);
5. It is forbidden to choose the national team.
$("input[name='nation']").attr("disabled",true);
6. Allowed to choose the national team.
$("input[name='nation']").attr("disabled",false);
7. Select the national team whose index is even or odd (the index starts from 0).
//选中索引为偶数的国家队 $("input[name='nation']:even").attr("checked",true); //选中索引为奇数的国家队 $("input[name='nation']:odd").attr("checked",true);
For more jQuery operation input type=checkbox implementation code related articles, please pay attention to the PHP Chinese website!