最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - activate select menu on hovermouseover using select2 - Stack Overflow

programmeradmin2浏览0评论

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,

Thanks all

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

Share Improve this question asked Jun 14, 2016 at 10:14 alexcalexc 1,3202 gold badges18 silver badges46 bronze badges 1
  • Duplicate of this and this – Mohammad Commented Jun 14, 2016 at 10:21
Add a ment  | 

2 Answers 2

Reset to default 5

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");
    }    
});

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");
});
发布评论

评论列表(0)

  1. 暂无评论