本文介绍了无法让typeahead.js工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

The input box shows up, but the typeahead feature dosn't work. It uses the latest jquery and typeahead.bundle.min.js libraries.

<!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路径.参见输入-示例

Try including full path to typeahead , using Bloodhound . See 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>

这篇关于无法让typeahead.js工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 20:09