jquery-textcomplete不工作

时间:2018-03-01 06:48:24

标签: jquery-ui-autocomplete

我试图使用jquery-textcomplete。但它根本不起作用。检查以下代码,请帮助我:

   <!DOCTYPE html>
<html>
    <head>
        <title>TODO supply a title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.textcomplete/1.8.4/jquery.textcomplete.min.js"></script>
        <style>
            body {
                background: #fff;
            }
        </style>
        <script>

            $('#textcomplete').textcomplete([{
                    words: ['anu', 'annamma', 'googlee', 'suresh namal', 'facebook', 'github', 'microsoft', 'yahoo', 'stackoverflow'],
                    match: /(^|\S*)([^\u0000-\u007f]{2,}|\w{2,})$/,
                    search: function (term, callback) {
                        console.log("inside search");
                        callback($.map(this.words, function (word) {
                            return word.indexOf(term) === 0 ? word : null;
                        }));
                    },
                    index: 2,
                    replace: function (word) {
                        return word + ' ';
                    }
                }]);

        </script>
    </head>
    <body>
        <div>
            <form>
                <textarea id="textcomplete"></textarea>
            </form>

        </div>
    </body>
</html>

我的小提琴:http://jsfiddle.net/anuannemariya/qys16w3d/3/

1 个答案:

答案 0 :(得分:0)

效果很好!

由于正则表达式/(^|\S*)([^\u0000-\u007f]{2,}|\w{2,})$/,您应输入至少2个字符。

如果要输入1个字符,可以像这样更改正则表达式: /(^|\S*)([^\u0000-\u007f]{1,}|\w{1,})$/