欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery實現(xiàn)Email郵箱地址自動補(bǔ)全功能代碼

 更新時間:2015年11月03日 10:48:54   作者:企鵝  
這篇文章主要介紹了jQuery實現(xiàn)Email郵箱地址自動補(bǔ)全功能代碼,涉及jQuery鼠標(biāo)事件及字符操作的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下

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

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

運行效果截圖如下:

在線演示地址如下:

http://demo.jb51.net/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相關(guān)字符自動提示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(){ //鼠標(biāo)經(jīng)過提示Email時,高亮該條Email
 $(".newemail").css("background","#FFF");
 $(this).css("background","#CACACA");
  $(this).focus();
  nowid = $(this).index();
 }).live("click",function(){ //鼠標(biāo)點擊Email時,文本框內(nèi)容替換成該條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程序設(shè)計有所幫助。

相關(guān)文章

  • jQuery判斷一個元素是否可見的方法

    jQuery判斷一個元素是否可見的方法

    這篇文章主要介紹了jQuery判斷一個元素是否可見的方法,涉及jQuery鏈?zhǔn)讲僮骷皹邮脚卸ǖ募记?需要的朋友可以參考下
    2015-06-06
  • jQuery查找節(jié)點方法完整實例

    jQuery查找節(jié)點方法完整實例

    這篇文章主要介紹了jQuery查找節(jié)點方法,結(jié)合完整實例形式分析了jQuery針對DOM節(jié)點屬性的相關(guān)操作技巧,需要的朋友可以參考下
    2016-09-09
  • jquery $.each() 使用小探

    jquery $.each() 使用小探

    jquery each想必大家對此并不陌生吧,它的使用范圍還是比較廣泛的,下面與大家分享個示例來介紹jquery each的使用方法,感興趣的朋友可以參考下,希望對大家有所幫助
    2013-08-08
  • jQuery 使用手冊(四)

    jQuery 使用手冊(四)

    jQuery 使用手冊,大家可以耐心的看完,就基本上入門了。
    2009-09-09
  • jQuery實現(xiàn)可展開合攏的手風(fēng)琴面板菜單

    jQuery實現(xiàn)可展開合攏的手風(fēng)琴面板菜單

    這篇文章主要介紹了jQuery實現(xiàn)可展開合攏的手風(fēng)琴面板菜單,涉及jQuery中slideUp及slideDown方法的相關(guān)使用技巧,代碼簡單實用,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-09-09
  • jquery實現(xiàn)Li滾動時滾動條自動添加樣式的方法

    jquery實現(xiàn)Li滾動時滾動條自動添加樣式的方法

    這篇文章主要介紹了jquery實現(xiàn)Li滾動時滾動條自動添加樣式的方法,實例分析了jquery響應(yīng)鼠標(biāo)事件及動態(tài)添加樣式的相關(guān)技巧,需要的朋友可以參考下
    2015-08-08
  • jQuery提示插件qTip2用法分析(支持ajax及多種樣式)

    jQuery提示插件qTip2用法分析(支持ajax及多種樣式)

    這篇文章主要介紹了jQuery提示插件qTip2用法,結(jié)合實例形式分析了qTip2的使用技巧,可支持ajax及多種樣式的設(shè)置,需要的朋友可以參考下
    2016-06-06
  • jquery實現(xiàn)的省市區(qū)三級聯(lián)動

    jquery實現(xiàn)的省市區(qū)三級聯(lián)動

    在做項目的時候,我們經(jīng)常需要用到地址之類的省市區(qū)三級聯(lián)動的,今天就給大家分享一個非常簡潔的省市區(qū)三級聯(lián)動的代碼,基于jQuery,附上GIT地址,有需要的小伙伴可以直接拿走
    2015-04-04
  • jQuery樹形控件zTree使用小結(jié)

    jQuery樹形控件zTree使用小結(jié)

    這篇文章主要為大家詳細(xì)介紹了jQuery樹形控件zTree使用方法,zTree樹插件的基本使用方法,感興趣的小伙伴們可以參考一下
    2016-08-08
  • JQuery將文本轉(zhuǎn)化成JSON對象需要注意的問題

    JQuery將文本轉(zhuǎn)化成JSON對象需要注意的問題

    在JQuery的許多方法中,很多方法的參數(shù)可以傳入一個JSON對象,比如Ajax方法的第二個參數(shù)。怎么將文本轉(zhuǎn)化成JSON對象,需要注意以下問題
    2011-05-05

最新評論