I have a select
element with a few option
elements, but the dropdown menu will not close after I open it.
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
This error at last version of select2, you can use the file I attached I edit focus event at 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() ||
to 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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.