jquery Operation <input type= "checkbox" >

Source: Internet
Author: User

<input type= "checkbox";:

12345 2012欧洲杯"死亡之组"小组出线的国家队是:<br><inputtype="checkbox" name="nation" value="Germany">德国<input type="checkbox" name="nation" value="Denmark">丹麦<input type="checkbox" name="nation" value="Holland">荷兰<inputtype="checkbox" name="nation" value="Portugal">葡萄牙

1, the first and second team to qualify, so to limit only two items to be selected.

12345678910111213 varlen = $("input[name=‘nation‘]:checked").length;if(len==0) {     alert("请选择出线的国家队!");     returnfalse;}elseif(len<2) {     alert("请选择两个国家队!");     returnfalse;}elseif(len>2) {     alert("只能选择两个国家队!");     returnfalse;}else{     returntrue;}

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";

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.