打开下拉列表时,防止select2自动聚焦于其搜索输入 [英] Prevent select2 from autmatically focussing its search-input when dropdown is opened
问题描述
我正在寻找一种方法,以防止在打开select2-下拉列表时对select2的搜索输入进行自动聚焦.我知道这是select2的预期默认行为-尽管这对于桌面客户端来说很好,但是我需要在iPad触发iPads软件键盘的情况下防止这种行为,这不是我们想要的默认行为.
I'm looking for a way to prevent select2's search-input being automatically focussed when the select2-dropdown is opened. I know this is select2's intended default behavior - and while this is fine for desktop clients, I need to prevent this behavior for the iPad where it triggers the iPads software keyboard, which is not what we want as a default.
我一直在寻找一个没有运气的选择. http://jsfiddle.net/KwW5n/2/反映了我们的设置-我们使用的是一个简单的-element作为我们select2功能的基础:
I've searched for an option to do so with no luck. http://jsfiddle.net/KwW5n/2/ reflects our setup - we're using a simple -element as a base for our select2-functionality:
$('#source').select2();
推荐答案
这在select2 v4上对我有用:
This worked for me on select2 v4:
// keep search input, but avoid autofocus on dropdown open
$('#research .filter').on('select2:open', function (e) {
$('.select2-search input').prop('focus',false);
});
信用转到此github评论
这篇关于打开下拉列表时,防止select2自动聚焦于其搜索输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!