好的,很简单,但我不知道怎么做。
我只想设置为活动状态(可能只是加粗)
我的菜单是ul-li
我想不出该怎么写,所以如果url与其中一个链接匹配,就把链接加粗。
请帮帮忙
耽误您时间,实在对不起
发布于 2010-12-15 03:28:02
下面是一种选择链接的快捷方法:
$('ul > li a[href$="' + window.location.pathname + '"]').css('font-weight','bold');或者像这样更好,它精确地匹配了两个pathname属性:
$('ul > li a[href]').filter(function() {
return this.href.pathname === window.location.pathname;
}).css('font-weight','bold');如果您在href中使用完整的域,则可以将其更改为:
return this.href === window.location;发布于 2015-09-30 02:53:40
这是我用过的一个很好的解决方案:
$(function(){
$("a").each(function(){
if ($(this).attr("href") == window.location.pathname){
$(this).addClass("selected");
}
});
});来源- https://css-tricks.com/snippets/jquery/highlight-all-links-to-current-page/
https://stackoverflow.com/questions/4443276
复制相似问题