如何清除focusout事件中的typeahead字段?
下面的jQuery代码在typeahead字段中似乎不起作用:
$( "#field" ).focusout(function() {
$(this).val("");
});发布于 2015-01-05 23:54:58
试试这个,这里是fiddle的例子
$('.typeahead').typeahead().bind('typeahead:close', function () {
$('.typeahead').typeahead('val', '');
});发布于 2017-08-25 20:29:13
可接受的答案现在已过期。查看latest Typeahead documentation可以看出捕获"close“事件和设置输入值是不同的。这是一个等价的更新后的答案:
$('.typeahead').typeahead().bind('typeahead:close', function() {
$('.typeahead').typeahead('val', '');
});发布于 2019-03-25 15:34:37
谢谢你的回答,但close事件对我不起作用,可能是我的设置或什么东西被弃用了。所以我写了这段代码,它工作得很好。
$('#typeahead-id').typeahead().bind('typeahead:selected', function() {
$('#typeahead-id').typeahead('val', '')
});https://stackoverflow.com/questions/27781213
复制相似问题