在我的 html 页面中,我尝试添加 Typeahead 以进行自动完成,但我无法解决与 TypeError 和 ReferenceError 相关的问题。
我在 CodePen 上尝试了一个示例,工作正常。 Click Here
但在实际页面中,我收到了这些错误。
错误
ReferenceError: _ is not defined
.mixin(Typeahead.prototype, {
typeahe...?body=1 (line 87, col 2)
TypeError: $(...).typeahead is not a function
HTML 代码
var subjects = ['PHP', 'MySQL', 'SQL', 'PostgreSQL', 'HTML', 'CSS', 'HTML5'];
$('#search').typeahead({source: subjects})
JS文件的排列
<%= javascript_include_tag 'jquery.js' %>
<%= javascript_include_tag 'angular.min.js' %>
<%= javascript_include_tag 'jquery-ui.min.js' %>
<%= javascript_include_tag 'bootstrap.3.2.js' %>
<%= javascript_include_tag 'typeahead.js' %>
<%= javascript_include_tag 'jquery.backstretch.min.js' %>
<%= javascript_include_tag 'jquery.scrollTo.min.js' %>
请提出一些建议来解决此问题。我在谷歌和 stackoverflow 上看到很少的解决方案,但没有任何效果。
请查看更新的答案区域
最佳答案
非常非常愚蠢的错误 - 也许我错了......
我发现我添加的 Bootstrap Javascript JS 文件存在问题。
在示例代码中,我添加了 bootstrap 2.3.2 版本并且工作正常。
twitter-bootstrap/2.3.2/js/bootstrap.min.js
但是在我的 html 页面中,我添加了 bootstrap 3.2 js 版本并按照我的假设创建了冲突。
<%= javascript_include_tag 'bootstrap.3.2.js' %>
现在我刚刚用 2.3.2 版本替换了 3.2 版本并且工作正常。
关于javascript - Typeahead + Jquery + TypeError : $(. ..).typeahead 不是函数 + .mixin(Typeahead.prototype,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26286209/