你可以尝试评估建议清单中正在分类的内容。 这样,他们就能够基本上选择使用“req.term”的打字。 与此类似:
//process response
$.each(data, function(i, val){
suggestions.push(val.name);
});
//append what has been typed in so it s available for selection
suggestions.push(req.term);
//pass array to callback
add(suggestions);
然后,在选择中:如果已经存在,你可以在数据库中加上“jax”电话。
//define select handler
select: function(e, ui) {
//create formatted friend
var friend = ui.item.value,
span = $("<span>").text(friend),
a = $("<a>").addClass("remove").attr({
href: "javascript:",
title: "Remove " + friend
}).text("x").appendTo(span);
//add friend to friend div
span.insertBefore("#to");
//insert selected email if doesn t already exists
},
在这里,在进入时插入您的模版朋友的一个关键例子:
$("#to").keypress(function(e){
var code = (e.keyCode ? e.keyCode : e.which);
if (code == 13) { //Enter keycode
e.preventDefault();
//create formatted friend
var friend = $(this).val(),
span = $("<span>").text(friend),
a = $("<a>").addClass("remove").attr({
href: "javascript:",
title: "Remove " + friend
}).text("x").appendTo(span);
//add friend to friend div
span.insertBefore("#to");
$(this).autocomplete( close );
}
});