gpt4 book ai didi

jquery - 设置预输入的选定值

转载 作者:行者123 更新时间:2023-12-03 22:12:58 24 4
gpt4 key购买 nike

我正在使用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);

最佳答案

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

jQuery#typeahead('setQuery', query)

Sets the current query of the typeahead. This is always preferable to using $("input.typeahead").val(query), which will result in unexpected behavior. To clear the query, simply set it to an empty string.

2016 更新(setQuery 不再存在):

jQuery#typeahead('val', val) Sets the value of the typeahead. This should be used in place of jQuery#val.

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

New documentation here

关于jquery - 设置预输入的选定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17278709/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com