我想在我的网站上使用自动填充/自动格式化的“收件人”字段,该字段的工作方式类似于GMail中的字段。
有谁知道jQuery这样的事情?
纯JavaScript?还是其他选择?
有很多的jquery位可以做到这一点,您可以在Google上搜索“ jquery autocomplete”,然后看看最喜欢哪个。
这是比较有名的一个: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>