Submenu stay open on menu click

后端 未结 1 1845
情书的邮戳
情书的邮戳 2021-02-01 11:20

I have a problem with js menu code. first let me explain what I try to do.

I have a menu with some items containing a submenu. The submenu\'s should open when a parent i

相关标签:
1条回答
  • 2021-02-01 12:10

    Ok I found the answer. This will fix it:

    $(document).ready(function()
    {  
       $('#topnav ul li ul.submenu li a').click(function(e){
         if ($(this).attr('class') != 'active'){
           $('#topnav ul li a').removeClass('active');
           $(this).addClass('active');
         }
       });
           $('a').filter(function(){
                return this.href === document.location.href;
           }).addClass('active')
           $("ul.submenu > li > a").each(function () {
             var currentURL = document.location.href;
             var thisURL = $(this).attr("href");
             if (currentURL.indexOf(thisURL) != -1) {
                 $(this).parents("ul.submenu").css('display', 'block');
             }
           });
           $('#topnav > ul > li > a').each(function(){
          var currURL = document.location.href;
          var myHref= $(this).attr('href');
          if (currURL.match(myHref)) {
                $(this).addClass('active');
                $(this).parent().find("ul.submenu").css('display', 'block');
          }
        });
    });
    
    0 讨论(0)
提交回复
热议问题