我正在使用连接到数据库的 jQuery 自动完成功能。现在,如果您开始输入术语并将鼠标移到填充的列表上,则原始术语的文本输入不会更改,直到您单击列表项。
我希望键盘也能发生同样的事情。键入向下箭头时不要填充文本框。使用回车
或鼠标单击
$(function() {
function log( message ) {
$(".userBookProjId").val(message);
$(".userBookProjId").scrollTop( 0 );
}
$( ".userBookProj" ).autocomplete({
source: "userBookProj.php?userId=" + $('#userId').val(),
minLength: 2,//search after two characters
select: function( event, ui ) {
log( ui.item ? ui.item.id : "");
}
});
});
非常感谢任何帮助!
最佳答案
您将需要使用focus
事件。
$(function() {
function log( message ) {
$(".userBookProjId").val(message);
$(".userBookProjId").scrollTop( 0 );
}
$( ".userBookProj" ).autocomplete({
source: "userBookProj.php?userId=" + $('#userId').val(),
minLength: 2,
focus: function(){
return false;
},
select: function( event, ui ) {
log( ui.item ? ui.item.id : "");
}
});
});
focus( event, ui )
Type: autocompletefocus
Triggered when focus is moved to an item (not selecting). The default action is to replace the text field's value with the value of the focused item, though only if the event was triggered by a keyboard interaction.
Canceling this event prevents the value from being updated, but does not prevent the menu item from being focused.
查看更多:http://api.jqueryui.com/autocomplete/
希望有帮助。
关于javascript - jQuery 自动完成 - 在选择之前不要填充文本输入(鼠标或输入),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54697415/