选择(Twitter)提前输入建议后,无法设置文本字段的值

这不起作用:

  $("#location").on("typeahead:selected", function(eventObject, suggestion, name) {
  console.log(suggestion.stop_id);
  $("#location").val(suggestion.stop_id);
});


尽管这可行:(但我想在同一文本字段中输入文本)

  $("#location").on("typeahead:selected", function(eventObject, suggestion, name) {
  console.log(suggestion.stop_id);
  $("#destination").val(suggestion.stop_id);
});

最佳答案

必须在typeahead的显示参数函数中将return null替换为return proposal.value以在字段中放入所需的值。

08-08 05:14