2009-10-07 215 views
2

我想要一个自动完成/ autoformat“To”字段在我的网站上运行,就像GMail中的一样。jQuery电子邮件地址输入

有没有人知道这种事情的jQuery?

Plain JavaScript?还是有其他的选择?

+0

我不得不从你的帖子中删除图片,因为ImageShack已经删除它并用广告代替它。有关更多信息,请参阅http://meta.stackexchange.com/q/263771/215468。如果可能的话,你可以重新上传它们。谢谢! – Undo

回答

1

有很多很多的jQuery位这样做,你可以谷歌的“jquery自动完成”,看看你最喜欢哪一个。

这里有一个是比较有名:http://docs.jquery.com/Plugins/AutoComplete

<script> 
    var emails = [ 
     { name: "Kitty Sanchez", to: "[email protected]" }, 
     { name: "Lucille Austero", to: "[email protected]" }, 
     { name: "Bob Loblaw", to: "[email protected]" }, 
     { name: "Sally Sitwell", to: "[email protected]" } 
    ]; 

    $(document).ready(function(){ 
     $("#Recipients").autocomplete(emails, { 
      multiple: true, 
      minChars: 1, 
      matchContains: "word", 
      autoFill: false, 
      formatItem: function(row, i, max) { 
       return "\"" + row.name + "\" &lt;" + row.to + "&gt;"; 
      }, 
      formatMatch: function(row) { 
       return row.name + " " + row.to; 
      }, 
      formatResult: function(row, i, max) { 
       return "\"" + row.name + "\" <" + row.to + ">"; 
      } 
     }); 
    }); 
</script> 
2

http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/

看看这个插件。它看起来相当健壮稳定,可能会满足您的需求。 jQuery是您寻求的效果的完美选择。请记住,根据你想从中获取数据的位置,你需要创建一些ajax/php后端。

+1

我想删除php部分,因为任何服务器端web技术/框架都可以使用 –

1

这些答案都很好,但我认为他正在寻找一些具体的事情电子邮件。 Gmail的电子邮件自动完成功能非常强大并且非常智能,可以考虑您最常收发电子邮件的人和其他因素。

+0

您可以在后端设计一些原始内容,假设有发送电子邮件的审核,并且您知道是谁发送了电子邮件,他们发送给谁。 –

相关问题