简体   繁体   English

单击主体时显示和隐藏菜单

[英]Show and Hide Menu When you Click on the body

<script>    

     $(".pagebg").on('click', function(d) {
        d.preventDefault();
        $("#dnnMenu").removeClass('nav-open');
        $("#google").removeClass('search-open');
    });

    </script>

I'm trying to Hide the Menu When I click outside of the div. 当我在div之外单击时,我试图隐藏菜单。 It does Exactly What I want it to do. 它确实正是我想要的。 But when I click on the links they don't work since when I click on the link it just thinks its the body and hides the menu. 但是,当我单击链接时,它们不起作用,因为当我单击链接时,它只是认为其主体并隐藏菜单。

Use stopPropagation method on the click event of your links/ menu div so it won't execute the click event of the outside container (body) 在链接/菜单div的click事件上使用stopPropagation方法,这样它就不会执行外部容器(主体)的click事件

 $(function(){

     $(".someLinks").click(function(e){
       e.stopPropagation();
       // to do : Hide or show
     });

 });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM