【发布时间】:2012-02-17 00:28:19
【问题描述】:
$(function() {
function split( val ) {
return val.split( /,\s*/ );
}
function extractLast( term ) {
return split( term ).pop();
}
$( "#names" ).autocomplete({
source: function(request, response) {
$.ajax({ url: "<?php echo site_url('update/suggestions'); ?>",
data: { term: extractLast( request.term )},
dataType: "json",
type: "POST",
success: function(data){
response(data);
},
focus: function() {
// prevent value inserted on focus
return false;
},
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( "," );
return false;
}
});
},
minLength: 2
});
});
上面的代码替换了现有的选择,而不是将新的选择添加到现有的选择中。这是在 Codeigniter 中。单个自动完成工作正常。 这不适用于多个输入字段,而是用于将多个值添加到单个输入字段。
【问题讨论】:
标签: jquery jquery-ui codeigniter autocomplete jquery-ui-autocomplete