【问题标题】:Set selected value of typeahead [closed]设置预先输入的选定值[关闭]
【发布时间】:2013-06-24 15:02:42
【问题描述】:

我正在使用twitter bootstrap typeahead

我已经自定义了字头,所以我可以选择一对值/标签

$.each(data.medicines,function(index,values){

    _med=new Object()
    _med.value=values.LYF
    _med.id=values.LYF_NUMER
    _medicines.push(_med)

})

//Fill typeahead with data
$('.typeahead').typeahead({
    // note that "value" is the default setting for the property option
    source:_medicines,
    onselect: function(obj) { showdetails(obj) }
})

如何使用 Javascript 设置选定的值?

For exemple $("#mytypehead").val(43);

【问题讨论】:

  • 为什么是 -1 ?

标签: jquery twitter-bootstrap bootstrap-typeahead


【解决方案1】:

根据the typeahead.js documentation on GitHub(比the bootstrap-typeahead.js docs in Twitter Bootstrap详细得多):

jQuery#typeahead('setQuery', 查询)

设置预输入的当前查询。这总是比使用$("input.typeahead").val(query) 更可取,这将导致意外行为。要清除查询,只需将其设置为空字符串即可。

2016 年更新(setQuery 不再存在):

jQuery#typeahead('val', val) 设置预先输入的值。 这应该用来代替 jQuery#val。

$('.typeahead').typeahead('val', myVal);

New documentation here

【讨论】:

  • @gpasse 确实如此。查看我的编辑。
  • 他们已将其更改为 jQuery#typeahead('val', query)
猜你喜欢
  • 1970-01-01
  • 2013-08-22
  • 2013-07-18
  • 2015-08-15
  • 2023-03-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多