jQuery的电子邮件地址输入
问题描述:
我想自动完成/自动式到在我的网站领域的作品像在Gmail中。
I'd like an autocomplete/autoformat "To" field on my web site that works like the one in GMail.
有谁知道这种事的jQuery?
Does anyone know of such a thing for jQuery?
普通的JavaScript?还是有其他的选择吗?
Plain JavaScript? Or any other alternatives?
答
有很多,很多的jQuery的比特做到这一点,你可以谷歌的jquery自动完成,看看你最喜欢的。
There are lots and lots of jquery bits that do this, you can google for "jquery autocomplete" and see which you like best.
下面是一个更出名: http://docs.jquery.com/Plugins/AutoComplete一>
<script>
var emails = [
{ name: "Kitty Sanchez", to: "kanchez@bluth.com" },
{ name: "Lucille Austero", to: "lucille2@balboatowers.net" },
{ name: "Bob Loblaw", to: "bloblaw@bobloblawlawblog.com" },
{ name: "Sally Sitwell", to: "sally@sitwell.org" }
];
$(document).ready(function(){
$("#Recipients").autocomplete(emails, {
multiple: true,
minChars: 1,
matchContains: "word",
autoFill: false,
formatItem: function(row, i, max) {
return "\"" + row.name + "\" <" + row.to + ">";
},
formatMatch: function(row) {
return row.name + " " + row.to;
},
formatResult: function(row, i, max) {
return "\"" + row.name + "\" <" + row.to + ">";
}
});
});
</script>