【问题标题】:jQuery - text field value change after jquery auto complete select eventjQuery - jQuery自动完成选择事件后文本字段值更改
【发布时间】:2012-05-01 22:54:21
【问题描述】:

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" />

【问题讨论】:

  • #found是什么类型的元素?
  • @AndrewWhitaker - 文本字段。 &lt;%= text_field_tag :found, nil, :maxlength =&gt; 11, :size =&gt; 20%&gt;
  • select 事件是否会触发?在处理程序中放置 alert 会发生什么?
  • @AndrewWhitaker - 是的 - 确实如此。如果我将其更改为 html &lt;a id="found"&gt;&lt;/a&gt;,那么它会很好地填充。
  • 它填充到 a 和 p 标签。但不输入标签。

标签: javascript jquery


【解决方案1】:

改变这一行:

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

到:

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

【讨论】:

  • 那行得通。我想在填充之前拆分它。如何拆分数据?
  • 你能解释一下“分裂”是什么意思吗?
猜你喜欢
  • 1970-01-01
  • 2011-12-05
  • 2014-11-19
  • 2012-01-07
  • 1970-01-01
  • 2015-03-17
  • 1970-01-01
  • 1970-01-01
  • 2012-09-25
相关资源
最近更新 更多