当悬停/聚焦于项目结果时,如何覆盖输入上显示项目标签的默认行为?
示例不起作用:
JavaScript的:
$('#ac').autocomplete({
source : ["hello", "how", "do", "you", "do"],
focus: function(event, ui){
console.log("print")
$(this).val('my custom label to show in input');
}
})
HTML:
<input type="text" id="ac"/>
答案 0 :(得分:4)
Prevent the default action of the event,用输入的值替换为焦点项的值:
$('#ac').autocomplete({
source : ["hello", "how", "do", "you", "do"],
focus: function(event, ui){
this.value = 'my custom label to show in input';
event.preventDefault(); // <-----
}
})