滚动选项列表时,突出显示的值不会显示在搜索框中。我使用的是jquery-ui版本1.10.3。 当我通过键盘选择它时它正常工作。
代码:
_createAutocomplete: function () {
var selected = this.element.children(":selected"),
selectedvalue = selected.text()
? selected.text() : "";
this.input = $("<input>")
.appendTo(this.wrapper)
.val(selectedvalue)
.attr("title", "")
.addClass("custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left")
.autocomplete({
minLength: 4,
source: $.proxy(this, "_source")
})
.tooltip({
tooltipClass: "ui-state-highlight"
});
this._on(this.input, {
autocompleteselect: function (event, orgselect) {
var newvar = this.input.val();
$("#control option").filter(function () {
return this.value == newvar;
}).attr('selected', true);
this.input.val($("#control option:selected").text());
},
autocompletechange: "_removeIfInvalid"
});
答案 0 :(得分:1)
使用jquery-ui focus
函数突出显示输入框中的值:
$( "#demo" ).autocomplete({
source: texts,
focus: function( event, ui ) {
$( "#demo" ).val( ui.item.label );
return false;
}
});