【发布时间】:2012-07-09 19:18:10
【问题描述】:
here 提供的 jQuery UI 自动完成多个示例允许您多次添加相同的项目。
如何防止这种情况发生?
【问题讨论】:
标签: jquery jquery-ui autocomplete jquery-autocomplete jquery-ui-autocomplete
here 提供的 jQuery UI 自动完成多个示例允许您多次添加相同的项目。
如何防止这种情况发生?
【问题讨论】:
标签: jquery jquery-ui autocomplete jquery-autocomplete jquery-ui-autocomplete
如果以 jQuery UI here 提供的示例为例,请在自动完成的 select 函数中添加以下行:
availableTags.splice($.inArray(ui.item.value, availableTags), 1);
这基本上删除了刚刚从可用标签列表中选择的项目。
你最终得到的选择函数应该是这样的:
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;
}
【讨论】: