JQuery operation & lt; input type = & quot; checkbox & quot; & gt;, jquerycheckbox

Source: Internet
Author: User

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

  

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.