我的 Shopify 网站顶部的菜单中有两个导航链接。菜单是在管理导航设置中创建/编辑的。我需要 #1 的菜单链接在网站的每个页面上保持突出显示,除非在 #2 页面上。
液体看起来像这样:
然后 html 呈现如下:
这个 javascript 让我部分地到达了那里,但是如果我离开主页,我就会丢失“当前”类。
$(function() {
$("a").each(function() {
if ($(this).prop("href") == window.location.href) {
$(this).addClass("current");
}
});
});
我正在寻找一种方法,将“当前”类保留在网站每个页面的第一个链接上,然后仅在该页面上时切换到第二个链接。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
if (window.location.href == 'https://yourdomain.com/pages/pl-pro') { $('#l1').removeClass ('current'); $('#l2').addClass ('current'); }.current { background-color: green; }Pure Luxury Beauty PL Pro