Jquery Autocomplete.js无法使用键盘上下箭头键
我正在使用以下jQueryUI自动完成功能。这是完美的工作与鼠标,但通过键盘,我不能选择任何值。看看代码Jquery Autocomplete.js无法使用键盘上下箭头键,jquery,jquery-autocomplete,Jquery,Jquery Autocomplete,我正在使用以下jQueryUI自动完成功能。这是完美的工作与鼠标,但通过键盘,我不能选择任何值。看看代码 $("#"+textBoxId).autocomplete("../common /autoSuggestValues.php?index="+index+"& randValue="+Math.random(), { selectFirst: false, width:textBoxWidth, minChars: 2, autoFill:
$("#"+textBoxId).autocomplete("../common
/autoSuggestValues.php?index="+index+"&
randValue="+Math.random(), {
selectFirst: false,
width:textBoxWidth,
minChars: 2,
autoFill: false,
scroll: true,
scrollHeight: 120,
formatItem: function (rowdata) {
var details = rowdata[0].split('@#@');
return details[0];
}
});
$('#'+textBoxId).result(function (event, data, formatted) {
var det = data[0].split("@#@");
if(det[0] != 'No Match Found') {
$('#'+textBoxId).val($.trim(det[0])).css('border','');
$('#'+hiddenId).val(det[1]);
processAutoSuggOptFunc(optionalFunction); //process the optional
function using the another built function "processAutoSuggOptFunc"
} else {
$('#'+textBoxId).val('');
$('#'+hiddenId).val('');
}
});
对我来说,提供聚焦方法可以解决以下问题:
searchField.autocomplete({
...
焦点:功能(事件、用户界面){
event.preventDefault();
jQuery(this.val)(ui.item.suggestion);
},
... });
另请参见此处:json是否返回结果?能否检查console中是否有任何错误?
事件。preventDefault()
至关重要,否则通过键盘选择仍将执行默认事件。