简体   繁体   English

下拉菜单-链接不起作用

[英]Dropdown Menu - Links do not work

I have a good working dropdown menu on my website, however, it didn't close when I clicked somewhere else on the page. 我的网站上有一个不错的下拉菜单,但是,当我单击页面上的其他位置时,菜单没有关闭。 It took me a while but I got this code written to get rid of this problem: 我花了一段时间,但是写了这段代码来解决这个问题:

$(document).ready(function(e) {
    $(".submenus").click(function( ) {
        $(this).toggleClass('tap');       
        return false;
     });

    $(document).click(function( ) {
    $(".submenus").removeClass('tap');
    });
 });

Now another new problem occurd. 现在又出现了另一个新问题。 Like I have said, the menu works perfectly, but since I have added this new code, the links within the menu do not open anymore when clicking on them, however, they do open when I right click and then open it in a new window. 就像我说的那样,菜单可以正常运行,但是由于我添加了此新代码,因此单击菜单时菜单中的链接不再打开,但是,当我右键单击并在新窗口中打开菜单时,链接确实会打开。 My assumption is that this new code closes the links before the code gives the website the task to open the link. 我的假设是,此新代码会在代码赋予网站打开链接的任务之前关闭链接。 That way it will try to open something it cant fint. 这样,它将尝试打开无法显示的内容。 That's my assumption, but do not know how I could solve this. 这是我的假设,但不知道如何解决。

Thanks for your help, Jan 谢谢您的帮助,扬

好了,由于上面收到的提示,我弄清楚了,我需要用“ event.stopPropagation();”代替“ return false”。

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

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