There are many ways to get the value of a form element in jquery. I will introduce in detail the examples and methods for getting the value of a form element in jquery, for more information, see.
Such as html
The Code is as follows: |
Copy code |
<Input type = "radio" value = "1" name = "radio_name"/> 1 <Input type = "radio" value = "2" name = "radio_name"/> 2 <Input type = "radio" value = "3" name = "radio_name"/> 3 Jquery $ ("Input [name = 'Radio _ name']: checked"). val () |
Some friends may not understand it. Let's take a look at val usage now.
Val ()
Obtains the current value of the First Matching Element.
In jQuery 1.2, the value of any element can be returned. Including select. If multiple values are selected, an array containing the selected values is returned.
Return Value
String, Array
/* Obtain the value of TEXT. AREATEXT */
The Code is as follows: |
Copy code |
Var textval = $ ("# text_id"). attr ("value "); // Or Var textval = $ ("# text_id"). val (); |
JQuery reads the value of the input element:
The Code is as follows: |
Copy code |
<Input type = "text" id = "keyword"/> |
The conventional approach is: $ ("# keyword "). the value cannot be obtained, because $ ('# keydord') is not an element but a jquery object, so you should use:
The Code is as follows: |
Copy code |
Var inputValue = $ ("# keyword"). val (); |
Because the first element in the Qjuery object is a DOM object, you can also set the value as follows:
The Code is as follows: |
Copy code |
Var inputValue = $ ("# keyword") [0]. value; |