用 jQuery 填充文本框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4889597/
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 18:07:46  来源:igfitidea点击:

Fill a textbox with jQuery

jquery

提问by Thomas

When I use this code, it doesn't want to work.

当我使用此代码时,它不想工作。

$('[id$=ADRESTextBox]').text(data[0]);

The data is an array as you can see. It really has a value (because I alerted it) How do you fill a certain textbox with jQuery.

如您所见,数据是一个数组。它真的有一个价值(因为我提醒过它)你如何用 jQuery 填充某个文本框。

回答by Felix Kling

Set values of form elements with val():

设置表单元素的值val()

$('[id$=ADRESTextBox]').val(data[0]);

If you are talking about text inputelements: They don't have "content" anyway. It is a single, self-closing tag, so any attempt to put something insidethe tag will fail. A text field's value is defined by its valueattribute.

如果您在谈论文本input元素:无论如何它们都没有“内容”。它是一个单一的,自闭的标签,因此任何企图把东西里面的标签将失败。文本字段的值由其value属性定义。

Update:

更新:

With respect to the comment: If ADRESTextBoxis actually the full ID, use $('#ADRESTextBox')to select the element.

关于注释:如果ADRESTextBox实际上是完整的ID,则用于$('#ADRESTextBox')选择元素。