0

このサイトのナビゲーション バーのアクティブなリンクとホバーの背景画像を保持しようとしています

サイトリンク: http://67.23.226.231/~edutubei/onepage/#about

以下のコードを使用して

$(document).ready(function() {
  $('#navigation a[href^="#' + location.pathname.split("#")[1] + '"]').addClass('current'); 
}); 

以下のcssで

ul.navigation .current{
  background:url(../images/current_page.png) no-repeat right bottom;
}    
ul.navigation .current a, ul.navigation .current a:hover{
  color:#FFF;
}

しかし、これは機能していません

4

1 に答える 1

0

あなたのセレクターは正しくありません。「#navigation」の代わりに「.navigation」にする必要があります

location.pathname は /~edutubei/onepage/ のみを返します。そのため、代わりに window.location.href を使用する必要があります。

 $('.navigation a[href="#' + window.location.href.split("#")[1] + '"]').addClass('current');
于 2013-04-05T19:22:26.527 に答える