我想知道是否有可能将类添加到与document.href具有相同href的链接?jQuery:活动状态:AddClass到包含document.href的链接href
我试过了,但没有任何运气。
if ($("a").attr("href") == document.location.href) {
$(this).addClass("active");
}
这不可能吗?
我想知道是否有可能将类添加到与document.href具有相同href的链接?jQuery:活动状态:AddClass到包含document.href的链接href
我试过了,但没有任何运气。
if ($("a").attr("href") == document.location.href) {
$(this).addClass("active");
}
这不可能吗?
$("a").filter(function() {
return this.href === document.location.href;
}).addClass("active");
应该工作。
你试过window.location.href而不是document.location.href吗?
$("a[href=" + document.location.href + "]").addClass("active");
(未测试)
我是怎么做的,但每对,过滤器是连招更好。 – 2011-05-17 19:50:34
谢谢! :-D这确实是可能的。 – 2011-05-17 20:26:54