我无法从jQuery UI Autocomplete的结果集中选择的项目在单击后显示在文本框中,但是我可以使用键盘浏览它们并使用enter键选择。这是我的代码:
$(document).ready(function () {
$('#t1').autocomplete({
source: function (request, response) {
// prepare url : for example '/api/artistapi?query=sonu
var autocompleteUrl = '/api/KeywordAutoComplete/' + request.term;
$.ajax({
url: autocompleteUrl,
type: 'GET',
cache: false,
dataType: 'json',
success: function (json) {
// call autocomplete callback method with results
response($.map(json, function (data, id) {
return {
label: data.KeyText
};
}));
},
error: function (xmlHttpRequest, textStatus, errorThrown) {
console.log('some error occured', textStatus, errorThrown);
}
});
},
minLength: 3,
select: function (event, ui) {
$('#autocomplete-textbox').val(ui.item.label);
return false;
}
});
我在Stackoverflow上遇到了一些类似的问题,但没有一个能解决我的问题。有人建议如果在标题部分加载多个JQuery-UI库,则会出现问题。这是我的标题:
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css" />
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
从我的标题中删除任何这些行都无济于事。谢谢大家