これにはほとんど3時間を費やしています。何も見つかりません。クラスを最寄りのdivに追加
ここに私のコードです..ファイルの3別のURL。 (更新)
<div id="menu">
<a href="blue.php">
<div class="list">
Content_here
</div>
</a>
<a href="yallow.php">
<div class="list">
Content_here
</div>
</a>
<a href="black.php">
<div class="list">
Content_here
</div>
</a>
</div>
は、ここで現在のURLに
<div id="menu">
<a href="#">
<div class="list active">
content_here
</div>
</a>
</div>
をクラスを追加します:現在のURL
上
$("#menu a").each(function(index) {
if($.trim(this.href) == window.location) {
$(this).closest('div').addClass("active");
}
});
ませんactive
class
。 div要素はa
使用children()
またはfind()
メソッド内でelement.Since ...
で、1以上があることに注意してくださいファイル上のURL。 – lovepeople
@lovepeopleあなたはすべてのURLを更新したいと思います....また、条件を '$ .trim(this.href)== '#'' –
に変更してください。@lovepeople:あなたの条件を '$(this).attr( 'href')== '#' ' –