jQuery Email Address Input

后端 未结 3 1321
天命终不由人
天命终不由人 2021-01-03 12:08

I\'d like an autocomplete/autoformat \"To\" field on my web site that works like the one in GMail.

Does anyone know of such a thing for jQuery?

Plain JavaScr

相关标签:
3条回答
  • 2021-01-03 12:24

    There are lots and lots of jquery bits that do this, you can google for "jquery autocomplete" and see which you like best.

    Here's one that is more famous: 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 + "\" &lt;" + row.to + "&gt;";
                },
                formatMatch: function(row) {
                    return row.name + " " + row.to;
                },
                formatResult: function(row, i, max) {
                    return "\"" + row.name + "\" <" + row.to + ">";
                }
            });
        });
    </script>
    
    0 讨论(0)
  • 2021-01-03 12:31

    These answers are fine but I think he's looking for something email specific. Gmail's email auto complete is very robust and smart taking into account like who you email most often and other factors.

    0 讨论(0)
  • 2021-01-03 12:48

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

    Check out this plugin. It appears to be quite robust and stable and may meet your needs. jQuery is a perfect choice for the kind of effect your seeking. Just keep in mind that, depending on where you want to get your data from, you'll need to create some sort of ajax/php backend.

    0 讨论(0)
提交回复
热议问题