【发布时间】:2017-04-25 21:51:35
【问题描述】:
我正在为我的项目使用 twitters typeahead 插件。在用户使用以下代码从自动完成建议的列表中进行选择后,我试图获取输入元素的值
我的html:
<body>
<input class="typeahead" type="text" placeholder="typeahead">
<script
src="https://code.jquery.com/jquery-3.2.1.js"
integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.2/bootstrap3-typeahead.js"></script>
<script src=" https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.2/bootstrap3-typeahead.min.js
"></script>
我的 JavaScript:
$(document).ready(function(){
var array = ["one", "two", "three", "four", "five"]
$(".typeahead").typeahead({source: array})
$('.typeahead').bind('typeahead:select', function(ev, suggestion) {
console.log('Selection: ' + suggestion);
});
});
自动完成功能完美无缺。但是,问题是在用户从自动完成建议中进行选择后,我无法获得输入的值。这是插件https://github.com/twitter/typeahead.js/blob/master/doc/jquery_typeahead.md 的文档 谁能帮我解决我的问题?
【问题讨论】:
标签: javascript jquery-plugins autocomplete cdn