【问题标题】:Can't get typeahead.js to work无法让 typeahead.js 工作
【发布时间】:2015-11-07 13:28:56
【问题描述】:

显示输入框,但预输入功能不起作用。它使用最新的 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>

【问题讨论】:

    标签: javascript jquery typeahead.js typeahead


    【解决方案1】:

    尝试使用 Bloodhound 包含到 typeahead 的完整路径。见Typeahead - Examples

    <!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>

    【讨论】:

      【解决方案2】:

      Typeahead 对我也不起作用,但 awesomplete 起作用了:

      https://github.com/LeaVerou/awesomplete

      【讨论】:

      • 感谢您的建议。我喜欢它,但它不允许“选项卡”完成部分识别的选择。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-23
      • 2014-12-26
      • 2017-12-22
      • 2012-02-28
      • 2015-12-01
      • 2012-01-29
      相关资源
      最近更新 更多