Close a menu with an anywhere click

后端 未结 5 2003
无人共我
无人共我 2021-01-06 17:18

As you guys can see, I have a drop down menu.

I have a lot of columns, each one has an option to open the menu.

$(\".optionCont\").live(\"click\", fu         


        
5条回答
  •  一个人的身影
    2021-01-06 18:04

    Register a one-off handler inside the callback to make sure the next click closes the menu:

    $(".optionCont").live("click", function(ev){
        $(".dropMenuCont").slideUp();
        if($(this).next().css("display") == "none"){
            $(this).next().slideDown();
        }else{
            $(this).next().slideUp();
        }
        ev.stopPropagation();
    
        $(document).one('click', function() {
                 $(".dropMenuCont").slideUp();
    
        });
    });
    

    See http://jsfiddle.net/alnitak/GcxMs/

提交回复
热议问题