【发布时间】:2020-02-06 03:09:42
【问题描述】:
我正在使用Bootstrap 3 Typeahead 4.0.2,我想知道在我选择列表中的一个项目后如何将 Typeahead 输入焦点更改为另一个输入文本?我发现了一些类似的问题,但我没有找到解决这个问题的正确方法:
- Angularjs ui typeahead to focus after select
- Focus on other input after typeahead-on-select angular-ui-bootstrap
- How to get Bootstrap typeahead click result before the input change event
当我在输入文本中选择某个项目时,焦点保持在此输入文本上,但我想在选择一个项目后将此焦点更改为下一个输入文本。下面是我正在使用的 html 代码和 bootstap typeahead:
HTML
<input type="text" name="products" id="products" data-provide="typeahead" class="form-control typeahead" autocomplete="off" placeholder="Type something" />
<input type="text" name="price" id="price" placeholder="Type price" />
Bootstrap 3 Typeahead
$('#products').typeahead({
source: function ( query, result )
{
result ( $.map(data, function (item)
{
return item.product;
}
));
},
afterSelect: function(data) {
$('#price').focus();
},
});
作为上面的 Typeahead 代码,我尝试在 Typeahead afterSelect 事件中插入 jquery 焦点事件 $('#price').focus(); 但不起作用。在这种情况下,我该如何解决?
【问题讨论】:
标签: jquery typeahead.js bootstrap-typeahead