简体   繁体   English

Select2下拉列表根本不会关闭

[英]Select2 dropdown won't close at all

I have a select element with a few option elements, but the dropdown menu will not close after I open it. 我有一个带有一些option元素的select元素,但打开它后,下拉菜单不会关闭。

I don't know why it doesn't work on my project but it works perfectly fine on a new project. 我不知道为什么它对我的项目不起作用,但它对新项目完全正常。

 $(document).ready(function() { $('#user-selection').select2(); }); 
 <select id="user-selection" name="userId" style="width: 100%" required> <option>1</option> <option>2</option> <option>3</option> </select> 

Am I missing something out? 我错过了什么吗?

Update: Changed to correct version of Select2 which made the problem go away 更新:更改为正确版本的Select2,使问题消失

This error at last version of select2, you can use the file I attached I edit focus event at select2.js 在最后一个版本的select2中出现此错误,您可以使用我附加的文件我在select2.js编辑焦点事件

this.on("focus", function () {
    a.$container.addClass("select2-container--focus"), 
    a.$container.hasClass("select2-container--disabled") || a.isOpen() && (a.options.get("multiple") ? window.setTimeout(function () {
        a.open()
    }, a.options.get("ajax") ? 300 : 100) : a.open())
}),

from a.isOpen() || 来自a.isOpen() || to a.isOpen() && a.isOpen() &&

 <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6/css/select2.min.css" rel="stylesheet"/> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://dits.cloud/js/select2.js"></script> <select id="user-selection" name="user" style="width: 100%" required> <option>1</option> <option>2</option> <option>3</option> </select> <script> $(document).ready(function () { $('#user-selection').select2(); }); </script> 

Edited select2.js 编辑了select2.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM