jQuery - 防止自动完成选择触发模糊()

m0d*_*0dE 14 jquery events jquery-ui blur jquery-ui-autocomplete

我正在尝试防止在选择时发生模糊:在自动完成中调用.(选择:在自动完成的建议框中单击项目时调用)但是,无意中,当我从建议框中选择项目时会调用模糊.我该如何解决这个问题?

这是我的代码基本排列的方式.

$("#input_field").autocomplete({
    source: "source.php",
    select: function( event, ui ) { alert("Item selected! Let's not trigger blur!"); }
}).blur(function(event) {
    alert("Alert if the user clicked outside the input, pressed enter, or tab button.");
    alert("But not from the item selection! :S");
});
Run Code Online (Sandbox Code Playgroud)

谢谢!

编辑:这是一个简短的背景.我试图允许用户搜索/选择项目或创建新项目,如果用户模糊输入.

Jon*_*der 20

自动完成jquery UI小部件带有一个"更改"事件,我认为这样做你想要的.除了在用鼠标选择项目时不调用它,它被称为模糊.

$("#input_field").autocomplete({
    source: "source.php",
    select: function( event, ui ) { alert("Item selected! Let's not trigger blur!"); }
});
$("#input_field").bind('autocompletechange', function(event, ui) {
    alert("Alert if the user clicked outside the input, pressed enter, or tab button.");
    alert("But not from the item selection! :S");
});
Run Code Online (Sandbox Code Playgroud)