国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

jQuery實現Email郵箱地址自動補全功能代碼

2019-11-20 11:21:09
字體:
來源:轉載
供稿:網友

本文實例講述了jQuery實現Email郵箱地址自動補全功能代碼。分享給大家供大家參考,具體如下:

jQuery Email郵箱地址自動補全代碼,輸入Email時,會自動加入@符號,在輸入框中輸入“qq”、“Sina”、“163”等等可以看到效果;鼠標經過提示Email時,高亮該條Email,鼠標點擊Email時,文本框內容替換成該條Email,并刪除提示層.

運行效果截圖如下:

在線演示地址如下:

http://demo.VeVB.COm/js/2015/jquery-email-auto-comp-codes/

具體代碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>輸入Email相關字符自動提示Email地址</title><script src="jquery-1.6.2.min.js" type="text/javascript"></script><style type="text/css">body{ margin:0px; padding:0px; font-family:Arial; font-size:12px; padding:10px;}#myemail, .newemail, .newemailtitle{  cursor:default; line-height:18px;}</style></head><body>Email <input id="me" type="text" value="" style="width:150px; height:18px; line-height:18px; border:1px solid #999;"><script type="text/javascript">var nowid;var totalid;var can1press = false;var emailafter;var emailbefor;$(document).ready(function(){  $("#me").focus(function(){ //文本框獲得焦點,插入Email提示層 $("#myemail").remove(); $(this).after("<div id='myemail' style='width:170px; height:auto; background:#fff; color:#6B6B6B; position:absolute; left:"+$(this).get(0).offsetLeft+"px; top:"+($(this).get(0).offsetTop+$(this).height()+2)+"px; border:1px solid #ccc;z-index:5px; '></div>"); if($("#myemail").html()){  $("#myemail").css("display","block"); $(".newemail").css("width",$("#myemail").width());  can1press = true; } else {  $("#myemail").css("display","none");  can1press = false; }   }).keyup(function(){ //文本框輸入文字時,顯示Email提示層和常用Email  var press = $("#me").val();  if (press!="" || press!=null){  var emailtxt = "";     var emailvar = new Array("@163.com","@126.com","@yahoo.com","@qq.com","@sina.com","@gmail.com","@hotmail.com","@foxmail.com");  totalid = emailvar.length;   var emailmy = "<div class='newemail' style='width:170px; color:#6B6B6B; overflow:hidden;'><font color='#D33022'>" + press + "</font></div>";   if(!(isEmail(press))){    for(var i=0; i<emailvar.length; i++) {     emailtxt = emailtxt + "<div class='newemail' style='width:170px; color:#6B6B6B; overflow:hidden;'><font color='#D33022'>" + press + "</font>" + emailvar[i] + "</div>"    }   } else {    emailbefor = press.split("@")[0];    emailafter = "@" + press.split("@")[1];    for(var i=0; i<emailvar.length; i++) {     var theemail = emailvar[i];     if(theemail.indexOf(emailafter) == 0)     {      emailtxt = emailtxt + "<div class='newemail' style='width:170px; color:#6B6B6B; overflow:hidden;'><font color='#D33022'>" + emailbefor + "</font>" + emailvar[i] + "</div>"     }    }   }   $("#myemail").html(emailmy+emailtxt);   if($("#myemail").html()){     $("#myemail").css("display","block");     $(".newemail").css("width",$("#myemail").width());     can1press = true;   } else {     $("#myemail").css("display","none");     can1press = false;   }   beforepress = press;  }  if (press=="" || press==null){   $("#myemail").html("");     $("#myemail").css("display","none");   } }) $(document).click(function(){ //文本框失焦時刪除層 if(can1press){   $("#myemail").remove();   can1press = false;   if($("#me").focus()){    can1press = false;   }  } }) $(".newemail").live("mouseover",function(){ //鼠標經過提示Email時,高亮該條Email $(".newemail").css("background","#FFF"); $(this).css("background","#CACACA");  $(this).focus();  nowid = $(this).index(); }).live("click",function(){ //鼠標點擊Email時,文本框內容替換成該條Email,并刪除提示層 var newhtml = $(this).html(); newhtml = newhtml.replace(/<.*?>/g,""); $("#me").val(newhtml); $("#myemail").remove(); }) $(document).bind("keydown",function(e) {  if(can1press){   switch(e.which)    {    case 38:    if (nowid > 0){     $(".newemail").css("background","#FFF");     $(".newemail").eq(nowid).prev().css("background","#CACACA").focus();     nowid = nowid-1;    }    if(!nowid){     nowid = 0;     $(".newemail").css("background","#FFF");     $(".newemail").eq(nowid).css("background","#CACACA");       $(".newemail").eq(nowid).focus();        }    break;     case 40:    if (nowid < totalid){     $(".newemail").css("background","#FFF");     $(".newemail").eq(nowid).next().css("background","#CACACA").focus();      nowid = nowid+1;    }    if(!nowid){     nowid = 0;     $(".newemail").css("background","#FFF");     $(".newemail").eq(nowid).css("background","#CACACA");       $(".newemail").eq(nowid).focus();        }    break;     case 13:    var newhtml = $(".newemail").eq(nowid).html();    newhtml = newhtml.replace(/<.*?>/g,"");    $("#me").val(newhtml);     $("#myemail").remove();   }  }  })}) //檢查email郵箱function isEmail(str){ if(str.indexOf("@") > 0)  {  return true; } else { return false; }}</script>在輸入框中輸入“qq”、“Sina”、“163”等等可以看到效果</body></html>

希望本文所述對大家jQuery程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 马鞍山市| 游戏| 嘉峪关市| 玉龙| 西城区| 特克斯县| 思茅市| 崇明县| 枣阳市| 兴业县| 齐河县| 莲花县| 福安市| 明水县| 河西区| 水城县| 宁化县| 同德县| 盐亭县| 乳山市| 米泉市| 临沭县| 苍溪县| 寿光市| 镇康县| 平昌县| 茂名市| 靖远县| 庐江县| 丽水市| 新巴尔虎左旗| 白山市| 香河县| 昭通市| 灌阳县| 宜都市| 大姚县| 县级市| 临猗县| 合江县| 临沂市|