Home > Web Front-end > JS Tutorial > How to use Jquery to get the selected radio value in the Form_jquery

How to use Jquery to get the selected radio value in the Form_jquery

WBOY
Release: 2016-05-16 17:26:01
Original
1226 people have browsed it

The selector provided by Jquery greatly facilitates developers to operate Dom, truly achieving the goal of code simplification but powerful functionality. The following is a small example of how to obtain the selected Radio value in the Form form, which is most commonly used in daily life.

The form is as follows:

Copy code The code is as follows:

< form name='form1' action="#" method="post">

Omit 200 words here
Shelve

Resolve

Transfer 4



So how to get the selected radio value? , Juqery provides us with the following methods
Copy code The code is as follows:

$( "input[name='opType']:checked").val() -------This method is probably used more often and is easy to understand

$("input:radio:checked" ).val(); ---------This method is the simplest, but it is not easy to understand using the selector continuously
$("input[@name='opType'][checked]"); -------- Remember to write [@checked=checked] in this method. I wrote this for the first time

So, occasionally I need to traverse the radio, how to do it? Of course, each needs to appear, as follows:
Copy code The code is as follows:

$(' input[name="opType"]').each(function(){
alert(this.name this.value);
});

should Understand it. If there is any better way, you are welcome to build a building.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template