【问题标题】:TypeError: $ (...).typeahead is not a function even including typehead.jsTypeError: $ (...).typeahead 不是一个函数,甚至包括 typehead.js
【发布时间】:2016-06-24 10:48:35
【问题描述】:
 <html>
   <head>
   <script src="js/typeahead.js"></script>
   <script>
        $(document).ready(function() {

            $('input.doctor').typeahead({
                name: 'doctor',
                remote: 'doctor.php?query=%QUERY'

            });

        })
    </script>
   </head>
   <body>
   <form>
   <input type="text" name="doctor" size="30" class="doctor"        placeholder="Please Enter City or ZIP code">
     </form>
   </body>
   </html>

error TypeError: $(...).typeahead 不是函数 我还包括 typehead.js 文件

【问题讨论】:

  • 您忘记在typeahead.js 之前添加jQuery

标签: javascript typeahead.js


【解决方案1】:

这是因为您没有包含jQuery 库,此步骤是必需的,因为typeahead需要jQuery 才能工作

在这里,试试这个:

<!DOCTYPE html>
<html>
  <head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-3.0.0.min.js"></script>
    <script type="text/javascript" src="//netsh.pp.ua/upwork-demo/1/js/typeahead.js"></script>
    <script type="text/javascript">
      jQuery(document).ready(function($) {
        $("input.doctor").typeahead({
          name: "doctor",
          remote: "doctor.php?query=%QUERY"
        });
      });
    </script>
  </head>
  <body>
    <form>
      <input type="text" name="doctor" size="30" class="doctor" placeholder="Please Enter City or ZIP code" />
    </form>
  </body>
</html>

【讨论】:

    【解决方案2】:

    请记住,您正在尝试将我的网站用作脚本的来源。我的意思是这一行:

    <script src="//netsh.pp.ua/upwork-demo/1/js/typeahead.js"></script>
    

    请使用 Google 查找此脚本的 CDN 或将您的主机用作脚本存储。 请将此链接用作脚本的源代码

    https://cdnjs.cloudflare.com/ajax/libs/jquery-typeahead/2.10.6/jquery.typeahead.js
    

    【讨论】:

      猜你喜欢
      • 2015-02-13
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-11
      • 2017-08-24
      相关资源
      最近更新 更多