jquary autocomplete 实现qq邮箱收件人

需要的js,css(远程的链接复制直接使用,下载请自行复制)
 

<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

html
 

<div class="ui-widget">
  <label for="tags">领导:</label>
  <input id="tags"/>
</div>
<div class="ui-widget">
  <label for="tagsub">抄送:</label>
  <input id="tagsub"/>
</div>

js
 

<script>
  $(function() {
    var autoVal = [];
    //数据格式最好以一个符号分割,用于下面open函数分割数组用
    var availableTags = [
      "王哥;",
      "居;",
      "tomy;",
      "陈彪;",
      "陈涛;",
      "冯涛;",
      "谭茹丹;",
      "老司机;",
      "威哥;",
      "周洁;",
      "紫阳;",
      "教练;",
      "维克多;",
      "春哥;",
      "钱老板;",
      "俊杰;",
      "国强;",
      "PHP;",
      "Python;",
      "Ruby;",
      "Scala;",
      "Scheme;"
    ];
    $("#tags").autocomplete({
      source: availableTags
    });
    $("#tagsub").autocomplete({
      source: function( request, response ) {
        var a=$.ui.autocomplete.escapeRegex( request.term );
        var newdata= a.split(';')
        var matcher = new RegExp( "^" + newdata[newdata.length-1], "i" );
        response($.grep( availableTags, function( item ){
          return matcher.test(item);
        }) );
      },
      //关闭函数,用于修改最终input的值
      close: function( event, ui ) {
        var val = $('#tagsub').val();
        autoVal.push(val);
        $('#tagsub').val(autoVal.join(''));
        console.log('close:' + autoVal.join(''));
      },
      //打开列表函数,需要保存删除后的数组
      open:function( event, ui ) {
        var val = $('#tagsub').val();
        var array=[];
        array=val.split(";");
        console.log('111:' + array.toString);
        if(array.toString().substring(array.toString().length-1,array.toString().length)==","){
          autoVal=[];
        }else {
          for (i = 0; i < array.length; i++) {
            array[i] = array[i] + ";";
          }
          if (array.length != 1) {
            array.splice(array.length - 1, 1);
            autoVal = array;
          }
        }
      }
    });
  });
</script>

转载于:https://my.oschina.net/maxdeath/blog/781888

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值