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

gen*_* b. 5 jquery jquery-select2

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

当选择框打开时,如果您尝试单击选择框级别之外的任意位置,它不会关闭。但是,如果您单击当前选择线的外部,则它会关闭。

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

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

$('#dropdown').select2({
    closeOnSelect: false
});
Run Code Online (Sandbox Code Playgroud)

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

Jua*_*llo 6

不知道是什么原因导致了这个问题,但是将其添加到您的 CSS 中可以“修复”它

选择2第4939期

html,
body{
  height: 100%;
}
Run Code Online (Sandbox Code Playgroud)

更新了代码

html,
body{
  height: 100%;
}
Run Code Online (Sandbox Code Playgroud)
/* 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,
});
Run Code Online (Sandbox Code Playgroud)
.select2-selection--multiple {
  height: 2rem;
  max-height: 2rem;
  overflow: auto;
}

html,
body {
  height: 100%;
}
Run Code Online (Sandbox Code Playgroud)