Getting an input element's value in jQuery
How c开发者_运维技巧an I get the value of an input element in jQuery?
If this is your textbox
:
<input type="text" id="mytextBox" value="" />
You will be getting it's value
using the textbox's ID=mytextBox
...
var value = $("#mytextBox").val()
References
- JQuery .val()
- JQuery
$("#elementId").val()
The best way is to use the val()
function, as in:
$('#someInput').val();
You can also use the attr function to find the value for some fields
$('#someInput').attr('value');
The val
function gets or sets the value of an input field.
Set the input value to "Hello world":
$('#myInput').val('Hello world');
Get the input value:
$('#myInput').val();
use jQuery('inputElement').val() to get the values of input(form) elements
精彩评论