使用jQuery将数组中的值读入输入文本字段

使用jQuery将数组中的值读入输入文本字段,jquery,Jquery,我有一个jQuery函数,它应该将数组中的值读取到文本字段。但是,我在将数组的零位置读入文本字段时遇到了一个问题 $(function(){ var values = ['one', 'two', 'three']; $('#room').val(values[0].text()); // not sure about this statement }); 这是我的html代码 <input id="room" /> text()用于将文本放入元素中

我有一个jQuery函数,它应该将数组中的值读取到文本字段。但是,我在将数组的零位置读入文本字段时遇到了一个问题

$(function(){
    var values = ['one', 'two', 'three'];
        $('#room').val(values[0].text());  // not sure about this statement
});
这是我的html代码

<input id="room" />

text()用于将文本放入元素中

$(function(){
    var values = ['one', 'two', 'three'];
        $('#room').val(values[0]);
});
text()的使用示例

你好,世界
$(“div”).text()//这将返回Hello World
text()用于将文本放入元素中

$(function(){
    var values = ['one', 'two', 'three'];
        $('#room').val(values[0]);
});
text()的使用示例

你好,世界
$(“div”).text()//这将返回Hello World