activate select menu on hover/mouseover using select2

◇◆丶佛笑我妖孽 提交于 2019-12-24 06:11:02

问题


I've been looking around the documentation to try find a way to easily activate the select menu on hover, and not only on click.

Unfortunately, I cannot seem to find the way to do it (if it exists), and was hoping someone could point me in the right direction?

Here is a plnk,

http://plnkr.co/edit/GTeyWfOp9aTd1B0Be0Hs?p=preview

Thanks all


回答1:


Try this:

$("#myselect").next(".select2").mouseenter(function() {
    $("#myselect").select2("open");
});
$(document).on("mouseleave", ".select2-container", function(e) {
    if ($(e.toElement || e.relatedTarget).closest(".select2-container").length == 0) {
        $("#myselect").select2("close");
    }    
});



回答2:


My generic solution to open and close select2 on mouseenter and mouseleave

$(document).on('mouseenter', '.select2-container', function(e) {
    $(this).prev("select").select2("open");
});

$(document).on('mouseleave', '.select2-container .select2-dropdown', function(e) {
    var selectId = $(this).find("ul").attr('id').replace("select2-", "").replace("-results", "");
    $("#"+selectId).select2("close");
});


来源:https://stackoverflow.com/questions/37809145/activate-select-menu-on-hover-mouseover-using-select2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!