[英]Can't display the selected item in the text input field with twitter-bootstrap typeahead
我正在使用bootstrap的預輸入自動完成
我可以使用以下代碼從服務器成功獲取項目列表,並從下拉列表中看到建議字:
$('.search-field').typeahead({
source: function( query, process ){
var queryParameters = form_params(document.getElementById("search"));
var inputid = this.$element.attr('id');
$.getJSON(
"GET DATA From SERVER"
}));
});
},
minLength: 1,
updater:function(item){
var id = this.$element.attr('id');
$('#'+id).val(item);
$('#'+id).text(item);
console.log($('#'+id));
instantSearch();
}
});
問題出在更新程序中。 當我在下拉列表中選擇一項時,item參數是我選擇的正確字符串。 我想在輸入文本字段中顯示選定的項目,但是什么也沒有發生。 都
$('#'+id).val(item);
和
document.getElementById('id').value = item;
失敗。
有誰知道如何在引導程序的預輸入更新程序中設置文本輸入字段的值?
動態設置選擇器很困難,我不確定您可以做到,但是值得一試:嘗試:
var itemSelect = "'#" + id + "'";
$(itemSelect).val(item);
要么
var itemSelect = document.getElementById(id);
itemSelect.value(item);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.