繁体   English   中英

无法让typeahead.js工作

[英]Can't get typeahead.js to work

显示输入框,但预输入功能不起作用。 它使用最新的jquery和typeahead.bundle.min.js库。

<!doctype html>
<html lang="en">
<head>
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script src="typeahead.bundle.min.js"></script>

    <script type="text/javascript">
        $(document).ready(function () {

            $('.typeahead').typeahead({
                name: 'RealFood',
                source: ["Spinach", "Kale", "Coconut", "Avocado", "Banana", "Granola", "Beets"]
            });

        });
    </script>
</head>
<body>
    <div style="width: 1000px; height: 300px;">
        <div style="float: left; width: 500px">
            <h3>Hungry?</h3>
            <input class="typeahead" type="text" placeholder="Food Item" autocomplete="off">
        </div>
    </div>
</body>
</html>

尝试使用Bloodhound包括完整的预输入路径。 请参见Typeahead-示例

 <!doctype html> <html lang="en"> <head> <title></title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> </head> <body> <div style="width: 1000px; height: 300px;"> <div style="float: left; width: 500px"> <h3>Hungry?</h3> <input class="typeahead" type="text" placeholder="Food Item" autocomplete="off"> </div> </div> <script src="http://twitter.github.io/typeahead.js/releases/latest/typeahead.bundle.js"></script> <script type="text/javascript"> $(document).ready(function() { var food = new Bloodhound({ datumTokenizer: Bloodhound.tokenizers.whitespace, queryTokenizer: Bloodhound.tokenizers.whitespace, local: ["Spinach", "Kale", "Coconut", "Avocado", "Banana", "Granola", "Beets"] }); $('.typeahead').typeahead({ hint: true, highlight: true, minLength: 1 }, { name: 'RealFood', source: food }); }); </script> </body> </html> 

Typeahead也不适合我,但awesomplete可以:

https://github.com/LeaVerou/awesomplete

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM