jquery operation <input type= "Radio" >

Source: Internet
Author: User

jquery operation <input type= "Radio" >

<input type= "Radio" > as follows:

12345 <inputtype="radio" name="city" value="BeiJing">北京<input type="radio" name="city" value="TianJin">天津<input type="radio" name="city" value="NanJing">南京<input type="radio" name="city" value="YangZhou">扬州<inputtype="radio" name="city" value="SuZhou">苏州

1. Get the value of the selected radio:

1 $("input[name=‘city‘]:checked").val();

Use the element selector, then use the attribute filter name= ' city ', and finally use: checked select the selected element.

2. Set the selected state to the radio of the specified value:

1 $("input[name=‘city‘][value=‘YangZhou‘]").attr("checked",true);

Give Name= "City" and Value= "Yangzhou" Radio set the selected state.

3. Cancel the selected state of the Name= "City" Radio:

1 $(‘input[name="city"]:checked‘).attr("checked",false);

4. Get the number of radio of Name= "City":

1 $("input[name=‘city‘]").length;

5. Get Name= "City" and the index is even radio:

1 $("input[name=‘city‘]:even");

The index is starting from 0.

6. Get Name= "City" and the index is odd radio:

1 $("input[name=‘city‘]:odd");

The index is starting from 0.

7. Iterative Radio:

12345 $("input[name=‘city‘]").each(function(i,obj){    //i,迭代的下标,从0开始    //obj,当前的对象(HTMLInputElement),可以使用obj.value格式获取属性值    //$(this);当前jQuery对象,可以使用$(this).val()获取属性值});

Iterate name= the radio of "City".

8. Disable Radio:

1 $("input[name=‘city‘]").attr("disabled",true);

Disables the radio of Name= "City".

9. Enable Radio:

1 $("input[name=‘city‘]").attr("disabled",false);

Enable the radio of Name= "City".

jquery operation <input type= "Radio" >

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.