javascript - jQuery - jquery 自动完成选择事件后文本字段值更改

标签 javascript jquery

jquery 自动完成选择事件后的简单文本字段更改。我想拆分数据并将其显示在其他文本字段中。我正在尝试这个。这根本不会改变任何值。我需要在这里改变什么?

$(function() {
  $("#term").autocomplete({
    source: function (request, response) {
      $.post("/users/search", request, response);
    },
    minLength: 2,
    select: function(event, ui){
        $('#div2').html(ui.item.value); #doesn't populate with new text. 
        document.getElementById('#found').value="test"; #for test
        } #doesn't populate with new text. 
          #I want selected data to go here in the 'found' element id
  });
});

ruby /html-

<%= text_field_tag :found, nil, :maxlength => 11, :size => 20%>
<input id="found" maxlength="11" name="found" size="20" type="text" />

最佳答案

改变这一行:

document.getElementById('#found').value="test"; #for test

到:

$('#found').val('test');

关于javascript - jQuery - jquery 自动完成选择事件后文本字段值更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10405521/

相关文章:

javascript - Postman (JavaScript) - 如何根据 JSON 数组中的对象数量创建环境变量?

javascript - 在非 Angular jsp中包含带 Angular jsp时出错

javascript - html代码中div标签的错误消息

javascript - Angularjs 删除动态生成的行

javascript - jQuery 的 "each()"方法是 for 循环吗?

javascript - 如何从网址中删除#prettyphoto

jquery - 如何将 jQuery UI 日期选择器初始化为查询字符串中的日期?

javascript - 输入前执行onclick

javascript - 使此 JavaScript 代码变干的最优雅的方法

javascript - 自动滚动到“下一页”的顶部