【发布时间】:2017-10-26 22:35:01
【问题描述】:
我正在尝试集成 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"}
]);
}
});
而且它有效。
【问题讨论】:
标签: jquery twitter-bootstrap-3 typeahead twitter-typeahead