邮箱收件人效果(自动填充)

来源:互联网 发布:finale 软件 编辑:程序博客网 时间:2024/05/22 11:13

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>智能填写</title>
                            <style type="text/css" >   #multiinput {
    font-size:22px;
    border:1px #000 solid;
    font-weight:700;
   }
   #newInput {
    height:24px;
    font-size:22px;
    border:none;
   }
   #selection ul {
    margin:0;
    padding:0;
    border:1px solid #000;
    width:75px;
    border-top:0;
   }
   #selection li {
    list-style:none;
    margin:0;
    padding:0;
    height:24px;
    cursor:pointer;
    width:75px;
   }
   #multiinput a:hover  {
    background-color:#eee;
    cursor:text;
   }
   li.selected {
    background-color:#eee;
   }
  </style>
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  <script type="text/javascript"><!--
   var str = ['张学友','张信哲','刘德华','孙燕姿','周杰伦','张含韵','许飞','许巍','张宇','周星驰','唐朝乐队','迪克牛仔','郑伊健','陈小春','汪峰'];
   $(function(){
    //输入框获得焦点时
    $("#newInput").focus(function(){
     var textStr = ["<ul>"];
     for(var i = 0; i < str.length; i++){
      textStr.push('<li>' + str[i] + '</li>');
     }
     textStr.push("</ul>");
     textStr = textStr.join('');
     $("#selection").show().empty().append(textStr);
    })
    //输入框失去焦点时
    .blur(function(e){
     $("#selection").hide();
    })
    //按键按下时
    .keydown(function(e){
     if(e.keyCode == 8 && $(this).val().length == 0) {
      $(this).prev().remove();
     } else if(e.keyCode == 40) {
      move(true);
     } else if(e.keyCode == 38) {
      move(false);
     } else if(e.keyCode == 13) {
      $('<a>' + $('.selected').text() + ';</a>').insertBefore('#newInput');
      $('#newInput').val('').focus();
     }
    })
    //按键弹出时,进行搜索匹配。
    .keyup(function(e){
     if(e.keyCode == 40 || e.keyCode == 8 || e.keyCode == 38)
      return;
     var textStr = $(this).val();
     var reg = new RegExp('(?=[^@]+)[^@]*' + textStr + '[^@]*(?=@|$)','g');
     var arr = str.join("@").match(reg) || [];
     textStr = ['<ul>'];
     for(var i = 0; i < arr.length; i++) {
      textStr.push('<li>' + arr[i] + '</li>');
     }
     textStr.push('</ul>');
     textStr = textStr.join('');
     $("#selection").empty().show().append(textStr);
    });
    //li的背景效果
    $("#selection li").live("mouseover",function(){
     $(this).siblings().removeClass('selected').end().addClass('selected');
    })
    //li的选中事件
    .live("mousedown",function(){
     $('<a>' + $(this).text() + ';</a>').insertBefore("#newInput");
     $("#newInput").val('').focus(); 
    });
    
    $("#multiinput a").live('dblclick',function(){
     $(this).remove();
    });
   });
   function move(down) {
    var selected = $('.selected');
    if(down) {
     if(selected.length == 0) {
      $('#selection li:first').addClass('selected');
     } else {
      selected.removeClass('selected').next().addClass('selected');
     }
    } else {
     if(selected.length == 0) {
      $('#selection li:last').addClass('selected');
     } else  {
      selected.removeClass('selected').prev().addClass('selected');
     }
    }
   }
  
// --></script>
 </head>
 <body>
  <div id="multiinput">
   <a id="t"></a><input id="newInput" type="text" autocomplete="off"/>
  </div>
  <div>
   <div id="selection">
   </div>
  </div>
 </body>
</html>