gpt4 book ai didi

javascript - 访问子页面时将父菜单项设为粗体

转载 作者:行者123 更新时间:2023-11-30 13:20:56 26 4
gpt4 key购买 nike

我有以下代码,它为菜单项提供了“当前”类。然后我使用 font-weight:Bold;

设置样式
$(document).ready(function () {
var loc = window.location.href;
$("ul a").each(function() {
if (loc.indexOf($(this).attr("href")) != -1) {
$(this).addClass("current");
}
});
});

如果用户在子菜单 ul li a 中的页面上,我如何将名为 Bold 的类添加到根目录的父级 UL/LI水平?

这是结构,如果我在 Q&Z Group,那么关于我们需要加粗。 - http://jsfiddle.net/zZQy3/

最佳答案

var loc = window.location.href;
$("ul a").each(function() {
if (loc.indexOf($(this).attr("href")) != -1) {
$(this).addClass("current");
$(this).parent('li').parent('ul').addClass("Bold");
}
});

关于javascript - 访问子页面时将父菜单项设为粗体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10281805/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com