幾乎有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>
這裏是:
$("#menu a").each(function(index) {
if($.trim(this.href) == window.location) {
$(this).closest('div').addClass("active");
}
});
沒有active
class
當前URL
。 ... element.Since股利是a
使用children()
或find()
方法內
我更新了我的問題,有不止一個網上檔案。 – lovepeople
@lovepeople你想更新每一個網址....也改變你的條件爲'$ .trim(this.href)=='#'' –
@lovepeople:也改變你的條件爲'$(this).attr 'href')=='#'' –