我正在尝试防止在选择时发生模糊:在自动完成中调用.(选择:在自动完成的建议框中单击项目时调用)但是,无意中,当我从建议框中选择项目时会调用模糊.我该如何解决这个问题?
这是我的代码基本排列的方式.
$("#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)
谢谢!
编辑:这是一个简短的背景.我试图允许用户搜索/选择项目或创建新项目,如果用户模糊输入.
我正在尝试这样做http://jqueryui.com/autocomplete/#combobox 问题是,当我用鼠标移动选项时,选项将消失,它出现了建议:"x不匹配任何item"其中x是我在组合框中写的字母.现在我发布网站上的脚本:
(function( $ ) {
$.widget( "ui.combobox", {
_create: function() {
var input,
that = this,
wasOpen = false,
select = this.element.hide(),
selected = select.children( ":selected" ),
value = selected.val() ? selected.text() : "",
wrapper = this.wrapper = $( "<span>" )
.addClass( "ui-combobox" )
.insertAfter( select );
function removeIfInvalid( element ) {
var value = $( element ).val(),
matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( value ) + "$", "i" ),
valid = false;
select.children( "option" ).each(function() { …Run Code Online (Sandbox Code Playgroud)