Implementation Code of jQuery operation input type = radio

Source: Internet
Author: User

<Input type = "radio"> as follows:
Copy codeThe Code is as follows:
<Input type = "radio" name = "city" value = "BeiJing"> BeiJing
<Input type = "radio" name = "city" value = "TianJin"> TianJin
<Input type = "radio" name = "city" value = "NanJing"> NanJing
<Input type = "radio" name = "city" value = "YangZhou"> YangZhou
<Input type = "radio" name = "city" value = "SuZhou"> SuZhou

1. Obtain the value of the selected radio:

Copy codeThe Code is as follows: $ ("input [name = 'city']: checked"). val ();

Use the element selector, use the attribute Filter name = 'city', and use: checked to select the selected element.

2. Set the selected status for the specified radio value:

Copy codeThe Code is as follows: $ ("input [name = 'city'] [value = 'yangzhou ']"). attr ("checked", true );

Set the radio status for name = "city" and value = "YangZhou.

3. deselect the radio status of name = "city:

Copy codeThe Code is as follows: $ ('input [name = "city"]: checked'). attr ("checked", false );

4. Obtain the number of radio for name = "city:

Copy codeThe Code is as follows: $ ("input [name = 'city']"). length;

5. obtain radio with name = "city" and an even number of indexes:

Copy codeThe Code is as follows: $ ("input [name = 'city']: even ");

The index starts from 0.

6. Obtain the radio with name = "city" and an odd index:

Copy codeThe Code is as follows: $ ("input [name = 'city']: odd ");

The index starts from 0.

7. Iterative radio:

Copy codeThe Code is as follows: $ ("input [name = 'city']"). each (function (I, obj ){
// I, subscript of iteration, starting from 0
// Obj, the current object (HTMLInputElement). You can use the obj. value format to obtain the attribute value.
// $ (This); the current jQuery object. You can use $ (this). val () to obtain the attribute value.
});

Iteration name = "city" radio.

8. Disable radio:

Copy codeThe Code is as follows: $ ("input [name = 'city']"). attr ("disabled", true );

Disable radio for name = "city.

9. enable radio:

Copy codeThe Code is as follows: $ ("input [name = 'city']"). attr ("disabled", false );

Enable radio for name = "city.

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.