您可以使用代碼爲multiple values demo,有一個正則表達式來僅插入括號內的數字:
function extractLast(term) {
return split(term).pop();
}
function split(val) {
return val.split(/,\s*/);
}
$(function() {
var availableTags = [
"Max (1)",
"Paul (3)",
"John (7)",
"Jochen (11)",
"Chris (9)"
];
$("#tags") .autocomplete({
minLength: 0,
source: function(request, response) {
// We trim the search term before comparing to the source
request.term = $.trim(request.term);
// delegate back to autocomplete, but extract the last term
response($.ui.autocomplete.filter(
availableTags, extractLast(request.term)));
},
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 number between parentheses for the selected item
var num = ui.item.value.match(/\((\d+)\)/);
var value = num[1];
terms.push(value);
// add placeholder to get the comma-and-space at the end
terms.push("");
this.value = terms.join(",");
return false;
}
});
});
看到這裏的jsfiddle:http://jsfiddle.net/96Y2y/2/
你可以看一下http://ivaynberg.github.com/select2/作爲alternare – 2013-02-15 09:25:20
你可以看看選擇2 http://jsfiddle.net/arunpjoh ny/6pMAq/ – 2013-02-15 09:50:17