Problem with jQuery mouseleave firing when container has select box

后端 未结 9 2249
一整个雨季
一整个雨季 2021-02-13 23:47

I have a two containers -- one is nested inside of another. When I hover over the parent, I want the child container to appear. When I mouseout, I want the child container to f

9条回答
  •  故里飘歌
    2021-02-14 00:02

    In most cases you should simply be able to check to see if the event target was a select element, and only continue in the case that it wasn't. Seems much cleaner than the accepted solution, and worked well in my case.

    I've modified the fiddle: http://jsfiddle.net/Dygerati/uj3ZC/5/

    $('#parent-container').live("mouseenter", function() {
        var $this = $(this),
            $selectOptionsContainer = $this.find('#child-container');
        $selectOptionsContainer.stop().fadeTo('slow', 1.0);
    }).live("mouseleave", function(e) {
        if(e.target.tagName.toLowerCase() != "select") {
            var $this = $(this),
                $selectOptionsContainer = $this.find('#child-container');
            $selectOptionsContainer.stop().hide();
        }
    });
    

提交回复
热议问题