我正在尝试集成 Twitter typeahead.js,为此我从 https://github.com/twitter/typeahead.js 下载了库并包含typeahead.bundle.min.js
然后我添加了以下内容
<input type="text" class="form-control typeahead font-normal">
$('.typeahead').typeahead({
source: function(query, process) {
console.log(query);
}
});
问题是它确实触发了源函数,我希望它在控制台中打印查询。 它没有。
这里可能有什么问题?
谢谢。
以下解决方案有效。
如答案所示,我首先添加了以下库
- jquery.min.js
- typeahead.bundle.min.js (https://twitter.github.io/typeahead.js/(
- typeahead.jquery.min.js (https://twitter.github.io/typeahead.js/(
- bootstrap3-typeahead.min.js (https://github.com/bassjobsen/Bootstrap-3-Typeahead(
然后初始化了以下代码
$('.typeahead').typeahead({
source: function(query, process) {
process([
{id: "1", name: "Display name 1"},
{id: "2", name: "Display name 2"}
]);
}
});
它有效。
试试这个,你必须添加引导类型提前js
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.2/bootstrap3-typeahead.js"></script>
jsFiddle for the samehttps://jsfiddle.net/aa7zyyof/17/