【发布时间】:2014-02-10 08:24:10
【问题描述】:
我正在使用 bootstrap typeahead,我想知道,如何在单击 enter 按钮时提交它?换句话说,如果我在预先输入的输入中输入“hello”并按下回车,我将如何提交“hello”?
我已经做到了,所以预输入不会自动选择第一个结果。
这是我的代码:
<form method="POST" action="script.php">
<input name="typeahead_field" class="typeahead" data-provide="typeahead" autocomplete="off" type="text">
</form>
jQuery:
$('.typeahead').typeahead({
items: 10,
source: function (query, process) {
$.ajax({
url: 'typeahead.php',
type: 'POST',
dataType: 'JSON',
data: 'query=' + query,
success: function(data) {
process(data);
}
});
},
highlighter: function(data) {
// code that returns each result
return html;
},
updater: function(data) {
// code that redirects the user if they click the selection
},
});
请帮忙!
【问题讨论】:
标签: javascript jquery ajax twitter-bootstrap bootstrap-typeahead