我使用ajax自动完成功能选择多个值。
选择了多个值,但问题是它还接受之前选择的相同值。
我的脚本功能是
<script>
$(function() {
function split( val ) {
return val.split( /,\s*/ );
}
function extractLast( term ) {
return split( term ).pop();
}
var url = "<?php echo $this->createUrl('tasks/autocompletedeveloper') ?>";
$( "#developers" ).bind( "keydown", function( event ) {
if ( event.keyCode === $.ui.keyCode.TAB &&
$( this ).autocomplete( "instance" ).menu.active ) {
event.preventDefault();
}
})
.autocomplete({
minLength: 1,
source: function( request, response ) {
// delegate back to autocomplete, but extract the last term
$.getJSON(url, { term : extractLast( request.term )},response);
},
focus: function() {
// prevent value inserted on focus
return false;
},
select: function( event, ui ) {
var terms = split( this.value );
terms.pop();
terms.push( ui.item.value );
terms.push( "" );
this.value = terms.join( ", " );
return false;
}
});
});
</script>
我的HTML代码是
<div class="form-group">
<label>Developer</label>
<input id="developers" class="form-control" />
</div>
请帮我限制相同的值选择。