开发者

Getting an input element's value in jQuery

开发者 https://www.devze.com 2023-01-15 04:16 出处:网络
How c开发者_运维技巧an I get the value of an input element in jQuery?If this is your textbox: <input type=\"text\" id=\"mytextBox\" value=\"\" />

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

0

精彩评论

暂无评论...
验证码 换一张
取 消