• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

白珩

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

邮箱补全代码

 

$("#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);


},

)};

posted on 2016-03-26 22:49  白珩  阅读(195)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3