在 jQuery 中获取输入元素的值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3673961/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 15:53:43  来源:igfitidea点击:

Getting an input element's value in jQuery

jqueryformstextinputhtml-input

提问by Rakesh Sabbani

How can I get the value of an input element in jQuery?

如何在 jQuery 中获取输入元素的值?

回答by Garis M Suero

If this is your textbox:

如果这是您的textbox

<input type="text" id="mytextBox" value="" />

You will be getting it's valueusing the textbox's ID=mytextBox...

您将value使用文本框的ID=mytextBox...

var value = $("#mytextBox").val()

References

参考

回答by Bozho

$("#elementId").val()

回答by Kranu

The best way is to use the val()function, as in:

最好的方法是使用该val()函数,如下所示:

$('#someInput').val();

You can also use the attr function to find the value for some fields

您还可以使用 attr 函数查找某些字段的值

$('#someInput').attr('value');

回答by Konal

The valfunction gets or sets the value of an input field.

val函数获取或设置输入字段的值。

Set the input value to "Hello world":

将输入值设置为“Hello world”:

$('#myInput').val('Hello world');

Get the input value:

获取输入值:

$('#myInput').val();

回答by sushil bharwani

use jQuery('inputElement').val() to get the values of input(form) elements

使用 jQuery('inputElement').val() 获取 input(form) 元素的值