我已经使用了这个(见下面的代码)来加粗当前页面的链接。例如 http://somewebsite.com/parent-page/current-page(这些部分的名称用作示例)
这会将指向当前页面的所有链接加粗,但我想将其修改为粗体指向父页面的所有链接(http://somewebsite.com/parent-page):
jQuery(document).ready(function( $ ) {
$("header a").each(function(){
if ($(this).attr("href") == window.location.pathname){
$(this).addClass("current-second-menu");
}
});
});
答案 0 :(得分:1)
只是一个小小的改变
jQuery(document).ready(function( $ ) {
$("header a").each(function(){
// if ($(this).attr("href") == window.location.pathname){
if ($(this).attr("href") == window.location.pathname.slice(0, window.location.pathname.lastIndexOf('/'))){
$(this).addClass("current-second-menu");
}
});
});