2013-10-14 40 views
0

我有JS菜單在我的網頁使用此代碼:主動標籤和JS風格

$(document).ready(function() { 

    $("#topnav li").prepend("<span></span>"); //Throws an empty span tag right before the a tag 

    $("#topnav li").each(function() { //For each list item... 
     var linkText = $(this).find("a").html(); //Find the text inside of the <a> tag 
     $(this).find("span").show().html(linkText); //Add the text in the <span> tag 
    }); 

    $("#topnav li").hover(function() { //On hover... 
     $(this).find("span").stop().animate({ 
      marginTop: "-40" //Find the <span> tag and move it up 40 pixels 
     }, 250); 
    } , function() { //On hover out... 
     $(this).find("span").stop().animate({ 
      marginTop: "0" //Move the <span> back to its original state (0px) 
     }, 250); 
    }); 

}); 

如何添加不同風格的主動/電流鏈接/標籤?

感謝您的幫助!

+0

其中的代碼位,使鏈接/標籤主動/電流? –

回答

0

這樣做:

<script type="text/javascript" charset="utf-8"> 
    //<![CDATA[ 
     jQuery(function() { 
      jQuery('#topnav li').each(function() { 
       var href = jQuery(this).find('a').attr('href'); 
       if (href === window.location.pathname) { 
        jQuery(this).addClass('current'); 
       } 
      }); 
     }); 
    //]]> 
</script> 
+0

什麼都沒有發生。請提供更多幫助:/。 – user2878600

+0

不幸的是,不工作。我需要點擊當前菜單鏈接的不同風格... – user2878600