2011-05-17 57 views

回答

6
$("a").filter(function() { 
    return this.href === document.location.href; 
}).addClass("active"); 

应该工作。

+0

我是怎么做的,但每对,过滤器是连招更好。 – 2011-05-17 19:50:34

+0

谢谢! :-D这确实是可能的。 – 2011-05-17 20:26:54

0

你试过window.location.href而不是document.location.href吗?

1
$("a[href=" + document.location.href + "]").addClass("active"); 

(未测试)