2014-01-10 171 views
0

使用此處提供的解決方案How to highlight active page in a masterpage menu?我能夠讓我的活動菜單項在導航菜單上正確顯示。我正在使用VB.NET和一個主頁面。下面的代碼駐留在母版:突出顯示活動菜單選項

<script> 
     function equalHeight(group) { 
      tallest = 0; 
      group.each(function() { 
       thisHeight = $(this).height(); 
       if (thisHeight > tallest) { 
        tallest = thisHeight; 
       } 
      }); 
      group.each(function() { $(this).height(tallest); }); 
     } 

     jQuery(document).ready(function() { 
      App.init(); 
      // Call to set active menu selecttion 
      var str = location.href.toLowerCase(); 
      $(".nav li a").each(function() { 
       if (str.indexOf($(this).attr("href").toLowerCase()) > -1) { 
        $("li.active").removeClass("active"); 
        $(this).parent().addClass("active"); 
       } 
      }); 
      equalHeight($(".img-thumbnail")); 

     }); 
</script> 

新增:如果一個節(「工具」爲實例)有下它屬於多頁,你能想到的任何方式都在上面的代碼選擇正確的活躍菜單項?

回答

0

使用此Javascript

function LoadActiveMenu() 
    { 
     var str=location.href.toLowerCase(); 
     $("li a").each(function() { 
      if (str.indexOf($(this).attr("href").toLowerCase()) > -1) { 
       $("li.active").removeClass("active"); 
       $(this).parent().addClass("active"); 
      } 
     }); 
     $("li.active").parents().each(function(){ 
      if ($(this).is("li")){ 
       $(this).addClass("active"); 
      } 
     }); 
    } 

,並呼籲對身體負荷情況下,本功能類似下面

<body onload="LoadActiveMenu();"> 
</body>