Fio*_*ite 3 jquery jquery-ui autocomplete jquery-autocomplete jquery-ui-autocomplete
此处提供的jQuery UI自动完成多个示例允许您多次添加相同的项目.
我该如何防止这种情况发生?
如果您在此处获取 jQuery UI提供的示例,请在自动完成的select函数中添加以下行:
availableTags.splice($.inArray(ui.item.value, availableTags), 1);
Run Code Online (Sandbox Code Playgroud)
这基本上删除了刚从可用标签列表中选择的项目.
您最终得到的选择功能应如下所示:
select: function( event, ui ) {
var terms = split( this.value );
// remove the current input
terms.pop();
// add the selected item
terms.push( ui.item.value );
// add placeholder to get the comma-and-space at the end
terms.push( "" );
this.value = terms.join( ", " );
// remove added item from list of available items to select
availableTags.splice($.inArray(ui.item.value, availableTags), 1);
return false;
}
Run Code Online (Sandbox Code Playgroud)