[英]Prevent latest Twitter typeahed from closing when clicking on a suggestion?
Before flagging this question as duplicate please note I've checked out all of these links and none work with the latest version v0.11.1: 在将此问题标记为重复之前,请注意我已检查了所有这些链接,但没有一个与最新版本v0.11.1一起使用:
My typeahed contains a form with an input. 我的打字包含一个带输入的表单。 I need to not to close the dropdown when user click a suggestion.
当用户点击建议时,我不需要关闭下拉列表。
Is there a reliable way to prevent close? 是否有可靠的方法来防止关闭? The obvious way it's not working ( https://jsfiddle.net/gcgdqfxp/ ):
显而易见的是它不起作用( https://jsfiddle.net/gcgdqfxp/ ):
$('.typeahed').on('typeahead:select', function (event, obj) {
// not working
event.preventDefault();
// not working
return false;
});
typeahead:select – Fired when a suggestion is selected.
typeahead:select - 选择建议时触发。 The event handler will be invoked with 2 arguments: the jQuery event object and the suggestion object that was selected.
将使用2个参数调用事件处理程序:jQuery事件对象和所选的建议对象。
Yeah!!! 是啊! Found a solution looking at the source here the (undocumented) "typeahead:beforeselect" event is triggered before actually trigger the "typeahead:select", so it's easy to stop propagation ( https://jsfiddle.net/gcgdqfxp/2/ ) like:
找到一个查看源代码的解决方案这里 (未记录的)“typeahead:beforeselect”事件在实际触发“typeahead:select”之前触发,因此很容易停止传播( https://jsfiddle.net/gcgdqfxp/2/ )喜欢:
$('.typeahead').bind('typeahead:beforeselect', function (event) {
event.preventDefault();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.