标签:
$("#email").autocomplete({
delay:0,
//自动选中第一行
autoFocus:true,
source:function(request,response){
var hosts = ["qq.com","163.com","sina.com.cn","126.com","gmail.com","hotmail,com"],
term = request.term,
name = term,
host = "",
ix = term.indexOf("@"),
result=[];
//把输入的内容加进来
result.push(term);
//当有@时重新分用户名和域名
if(ix>-1){
name = term.slice(0,ix);
host = term.slice(ix+1);
}
if(name){
//如果用户输入@和后面的域名
//那么就显示提示域名
//如果还没有输入@或后面域名不存在则把所有都提示出来
var findHosts =(host ? $.grep(hosts,function(value,index){
return value.indexOf(host)>-1
}) : hosts),
findResult=$.map(findHosts,function(value,index){
return name+"@"+value;
});
result = result.concat(findResult);
}
response(result);
},
)};
标签:
原文地址:http://www.cnblogs.com/baiheng/p/5324387.html