Blur Select2 input after close

前端 未结 1 909
鱼传尺愫
鱼传尺愫 2020-12-19 12:33

I want the select2 element to lose the focus when the select2-close event is triggered, what I have tried so far was:

.on(\"select2-close\", function (e) {
          


        
相关标签:
1条回答
  • 2020-12-19 12:53

    You need to remove the .select2-container-active class from the containing divider:

    .on("select2-close", function () {
        setTimeout(function() {
            $('.select2-container-active').removeClass('select2-container-active');
            $(':focus').blur();
        }, 1);
    });
    

    I've used a setTimeout here as a hacky way to ensure that this triggers after the plugin itself finalises the close.

    JSFiddle demo.

    0 讨论(0)
提交回复
热议问题