我有bootstrap組合框在自動完成更改上我想選擇值,問題是,這隻適用於當我雙擊過濾結果內組合,如果我只點擊一次,我得到myselection變量空。自動完成和引導組合框
$('#MyComboId').on('change', function() {
var myselection = $(this).find("option:selected").val();
});
});
我有bootstrap組合框在自動完成更改上我想選擇值,問題是,這隻適用於當我雙擊過濾結果內組合,如果我只點擊一次,我得到myselection變量空。自動完成和引導組合框
$('#MyComboId').on('change', function() {
var myselection = $(this).find("option:selected").val();
});
});
如果我理解正確使用bootstrap-combobox
(Link)。
我發現二傳手代碼:
select: function() {
var val = this.$menu.find('.active').attr('data-value');
this.$element.val(this.updater(val)).trigger('change');
this.$target.val(this.map[val]).trigger('change');
this.$source.val(this.map[val]).trigger('change');
this.$container.addClass('combobox-selected');
this.selected = true;
return this.hide();
}
更新:
當用戶點擊下拉列表,從項目,change
事件將觸發,這是不正確。即輸入將被清除,之後它將被填充正確的值。
var el = $('.combobox').combobox();
el.on('change', function(e){
if($(this).data('combobox').$element.val() == ''){
console.log('Its triggered incorrectly');
return false;
}
var dic = $(this).data('combobox').map,
val = $(this).val(),
clean = true;
for(var i in dic){
if(!dic.hasOwnProperty(i)) continue;
if(dic[i] == val){
console.log(dic[i], i); // dic[i] = value, i = label
clean = false;
break;
}
}
if(clean)
console.log('Input was cleared');
})
其實這個你提供的jsfiddle鏈接實際上是我遇到的問題的完美例子。你看,當你從組合NewYork中選擇它時,它工作正常,但如果你鍵入New,然後嘗試從菜單中選擇New York,它不起作用。 – user1765862
@ user1765862請查看我更新的答案 –
你可以提供一個工作的例子嗎? – Dekel
這個https://jsfiddle.net/neceegbv/5/適合你的問題嗎? –