Javascript 如何仅在选中时显示自动完成选择?

Javascript 如何仅在选中时显示自动完成选择?,javascript,jquery,html,Javascript,Jquery,Html,我有一个JavaScript代码,它将提供自动完成预测 即使我将鼠标放在预测上,这段代码也会显示这个单词 实际上,我只需要在从列表中选择预测时显示它 请参见此处的演示: 这句话是什么意思?谁能给我解释一下吗 $(window).load(function(){ $('#tags').each(function(i, el) { var that = $(el); that.autocomplete({ select: funct

我有一个JavaScript代码,它将提供自动完成预测

即使我将鼠标放在预测上,这段代码也会显示这个单词

实际上,我只需要在从列表中选择预测时显示它

请参见此处的演示:

这句话是什么意思?谁能给我解释一下吗

$(window).load(function(){
    $('#tags').each(function(i, el) {
        var that = $(el);
        that.autocomplete({  
            select: function( event , ui ) {
                alert( "You searched for: " + ui.item.label );//alerting the selection to the user
            }
        });
    });
});

我想你可能让事情变得更难了

$("#tags").autocomplete({
    source: availableTags,
    focus : function(event) { event.preventDefault(); },
    select: function(event, ui) {
        alert( "You searched for: " + ui.item.label); //alerting the selection to the user
    }
});
应该足够了。防止在
焦点
事件上触发默认事件将防止鼠标悬停的元素显示在
#标记
输入中

$("#tags").autocomplete({
    source: availableTags,
    focus : function(event) { event.preventDefault(); },
    select: function(event, ui) {
        alert( "You searched for: " + ui.item.label); //alerting the selection to the user
    }
});