Javascript TypeError: $(...).typeahead 不是函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27478953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 00:11:53  来源:igfitidea点击:

TypeError: $(...).typeahead is not a function

javascriptjquerytwitter-bootstrapbootstrap-typeahead

提问by Aadam

This is very basic code. Still I am facing a problem. I think I am missing something, as mentioned on bootstrap site

这是非常基本的代码。我仍然面临一个问题。我想我错过了一些东西,如引导网站上所述

"Plugins can be included individually (though some have required dependencies), or all at once. Both bootstrap.js and bootstrap.min.js contain all plugins in a single file."

“插件可以单独包含(尽管有些插件需要依赖项),也可以同时包含。bootstrap.js 和 bootstrap.min.js 都在一个文件中包含所有插件。”

So I included boostrap.js and still getting that error, what are the other dependencies?

所以我包含了 boostrap.js 并且仍然得到那个错误,其他的依赖是什么?

Below is the code.

下面是代码。

<!DOCTYPE html>
<html>
    <head>
        <title>Member</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script type="text/javascript" src="js/jquery.js"></script>
        <script type="text/javascript" src="js/bootstrap.min.js"></script>
        <link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
    </head>
    <body>
<div class="well">  
<input type="text" class="span3" id="search" data-provide="typeahead" data-items="4" />  
</div>
<script>  
 var subjects = ['PHP', 'MySQL', 'SQL', 'PostgreSQL', 'HTML', 'CSS', 'HTML5', 'CSS3', 'JSON'];   
$('#search').typeahead({source: subjects})  
</script>
    </body>
</html>

Regards

问候

Aadam

亚当

采纳答案by Aamir Parre

if you see the error message "TypeError: $(…).typeahead is not a function" it mean typeahead function is not provided in the version of bootstrap you are using. Officially the typeahead is dropped from the new release 3.0. And is available separtely in typeahead.js.

如果您看到错误消息“TypeError: $(...).typeahead is not a function”,则表示您使用的引导程序版本中未提供 typeahead 功能。正式从新版本 3.0 中删除了预先输入。并且可以在 typeahead.js 中单独使用。

you need to include the the typeahead.js plugin the error will remove.

您需要包含错误将删除的 typeahead.js 插件。

回答by Shubham Verma

I have faced an Error like "TypeError: $(…).typeahead is not a function"

我遇到过类似“ TypeError: $(...).typeahead is not a function”这样的错误

Here typeahead function is not provided in bootstrap in current version that you are using.

在您使用的当前版本中,bootstrap 中未提供预先输入功能。

Now the typeahead is removedfrom the new release 3.0. and now this is available on typeahead.js.

现在typeahead从新版本 3.0 中删除。现在可以在 typeahead.js 上使用。

So you will have to include the the typeahead.js plugin in your file/project then your error will be remove.So include your reference to the typeahead function.

所以你必须在你的文件/项目中包含 typeahead.js 插件,然后你的错误将被删除。所以包括你对 typeahead 函数的引用。

( Download the latest bootstrap3-typeahead.js or bootstrap3-typeahead.min.js. Include it in your source after jQuery and Bootstrap's JavaScript. )

(下载最新的 bootstrap3-typeahead.js 或 bootstrap3-typeahead.min.js。在 jQuery 和 Bootstrap 的 JavaScript 之后将其包含在您的源代码中。)

Link To download:

链接下载:

https://github.com/bassjobsen/Bootstrap-3-Typeahead/blob/master/bootstrap3-typeahead.js

https://github.com/bassjobsen/Bootstrap-3-Typeahead/blob/master/bootstrap3-typeahead.js

See the snapshot for help

请参阅快照以获取帮助

https://github.com/bassjobsen/Bootstrap-3-Typeahead/blob/master/bootstrap3-typeahead.min.js

https://github.com/bassjobsen/Bootstrap-3-Typeahead/blob/master/bootstrap3-typeahead.min.js

See the snapshot to download the typehead.min.js

查看快照下载 typehead.min.js

回答by seceparsto

$('#search').typeahead({source: subjects}) 

should be

应该

$('#search').typeahead({local: subjects}) 

And since typeahead is no longer included in the latest standard Bootstrap package, you need to download and point to it explicitly. The download link: typeahead.js

由于 typeahead 不再包含在最新的标准 Bootstrap 包中,您需要下载并明确指向它。下载链接: typeahead.js

The latest version is 2015 so it has not been updated for a few years.

最新版本是2015年所以几年没更新了。