How to Use Jquery to obtain the selected radio value in Form _ jquery

Source: Internet
Author: User
The following is a small example of how to obtain the selected Radio Value in the Form, if you are interested, you can refer to the selector provided by Jquery, which greatly facilitates the Dom operations by developers and truly simplifies the code, but has powerful functions. The following is a small example of how to obtain the selected Radio Value in the Form that is most commonly used.

The form is as follows:

The Code is as follows:




Then, how can we obtain the selected radio value? Juqery provides the following methods for us:

The Code is as follows:


$ ("Input [name = 'optype']: checked"). val () ------- this method is widely used and easy to understand.

$ ("Input: radio: checked"). val (); --------- this method is the easiest, but it is not easy to understand when using selector.
$ ("Input [@ name = 'optype'] [checked]"); -------- write [@ checked = checked] In the power method. This is what I wrote for the first time.


Then, we also need to traverse radio occasionally. What should we do? Of course, each is required to appear, as follows:

The Code is as follows:


$ ('Input [name = "commandid condition opType"] '). each (function (){
Alert (this. name + this. value );
});


I should have understood it. If you have any better methods, you are welcome to build a building.

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.