单击外部时,Select2不会关闭选择框(closeOnSelect = false)

JSFiddle: http : //jsfiddle.net/xpvt214o/776660/

当选项框打开时,如果您尝试单击选项框级别任何位置,则不会关闭它。 但是,如果在Current-Selection行的级别上单击外部,则会关闭它。

当执行任何外部点击时,如何强制Select2选项框关闭,包括在选择框的级别上?

PS我正在使用closeOnSelect: false选项来保持选择框在选择过程中始终打开 – 但它仍应在外部点击时关闭,

 $('#dropdown').select2({ closeOnSelect: false }); 

另一个类似的问题 – 当closeonselect为false时,关闭select2

不知道导致问题的原因,但是将其添加到CSS中会“修复”它

选择2问题4939

 html, body{ height: 100%; } 

更新的代码

 /* Scroll CurrSel SPAN to bottom on every Select2 Select event */ $('#dropdown').on("select2:selecting", function(e) { var currselspan = $('#dropdown').next().find('.select2-selection--multiple').first(); console.log('scrollTop = ' + $(currselspan).scrollTop() + ' scrollHeight = ' + $(currselspan).prop('scrollHeight')); $(currselspan).scrollTop($(currselspan).prop('scrollHeight')); }); $('#dropdown').select2({ closeOnSelect: false, }); 
 .select2-selection--multiple { height: 2rem; max-height: 2rem; overflow: auto; } html, body { height: 100%; }