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

jQuery - text field value change after jquery auto complete select event

本文关键字:文本 字段 事件 选择 jquery jQuery      更新时间:2023-09-26

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');