gpt4 book ai didi

javascript - 添加基于 session URL 的事件导航类

转载 作者:行者123 更新时间:2023-11-27 23:56:11 25 4
gpt4 key购买 nike

我正在尝试将 .active 类 (font-weight:700;) 添加到事件页面导航菜单。

他们的系统 url 基于 session 和类别。

主页(已登录)- http://mrb-admin.xpeditefulfillment.com/v5fmsnet/OeCart/OeFrame.asp?PmSess1=1339143&SXREF=0&CurPath=1

导航菜单类别 1 - http://mrb-admin.xpeditefulfillment.com/v5fmsnet/OeCart/OeFrame.asp?PmSess1=1339143&SXREF=1

类别 2 - http://mrb-admin.xpeditefulfillment.com/v5fmsnet/OeCart/OeFrame.asp?PmSess1=1339143&SXREF=2

任何帮助我指明正确方向以捕获 URL 末尾的类别以应用 .active 类的方法都会很棒。

谢谢瑞安

<div id="SbCatMenu">
<dl id="dlCatLvl1" class="clsCatLvl1 clsOffCat1">
<dd class="clsCatTree1 clsCTree1" id="CatImg1"><a href="../OeCart/OeFrame.asp?PmSess1=1338988&amp;SXREF=1">Apparel<span class="clsCatOffCount"> 15</span></a></dd>
<dd class="clsCatTree1 clsCTree1" id="CatImg2"><a href="../OeCart/OeFrame.asp?PmSess1=1338988&amp;SXREF=2">Events<span class="clsCatOffCount"> 23</span></a></dd>
<dd class="clsCatTree1 clsCTree1" id="CatImg3"><a href="../OeCart/OeFrame.asp?PmSess1=1338988&amp;SXREF=3">Giveaways<span class="clsCatOffCount"> 1</span></a></dd>
<dd class="clsCatTree1 clsCTree1" id="CatImg4"><a href="../OeCart/OeFrame.asp?PmSess1=1338988&amp;SXREF=4">Glassware<span class="clsCatOffCount"> 2</span></a></dd>
<dd class="clsCatTree1 clsCTree1" id="CatImg5"><a href="../OeCart/OeFrame.asp?PmSess1=1338988&amp;SXREF=5">In Store Tastings<span class="clsCatOffCount"> 1</span></a></dd>
<dd class="clsCatTree1 clsCTree1" id="CatImg6"><a href="../OeCart/OeFrame.asp?PmSess1=1338988&amp;SXREF=6">Misc<span class="clsCatOffCount"> 1</span></a></dd>
<dd class="clsCatTree1 clsCTree1" id="CatImg7"><a href="../OeCart/OeFrame.asp?PmSess1=1338988&amp;SXREF=7">On Premise<span class="clsCatOffCount"> 3</span></a></dd>
<dd class="clsCatTree1 clsCTree1" id="CatImg8"><a href="../OeCart/OeFrame.asp?PmSess1=1338988&amp;SXREF=8">Print<span class="clsCatOffCount"> 1</span></a></dd>
<dd class="clsCatTree1 clsCTree1" id="CatImg9"><a href="../OeCart/OeFrame.asp?PmSess1=1338988&amp;SXREF=9">Retail<span class="clsCatOffCount"> 7</span></a></dd>
<dd class="clsCatTree1 clsCTree1" id="CatImg10"><a href="../OeCart/OeFrame.asp?PmSess1=1338988&amp;SXREF=10">Retail/ Events<span class="clsCatOffCount"> 1</span></a></dd>
</dl>

</div>

这是我尝试过但没有成功的方法-

$

(function(){

//this returns the whole url

var current = window.location.href;
console.log(current)

//this identifies the list you are targeting

$('#dlCatLvl1 dd a').each(function(){
var $this = $(this);
console.log(this)

// if the current path is exactly like this link, make it active

if($this.attr('href') === current){
$this.css('color', 'red');
}
})
});

最佳答案

尝试匹配而不是比较值:

if(current.match($this.attr('href').replace('..', '') !== null){     
$this.css('color', 'red');
}

因为您的 href 值都以 ../OeCart/OeFrame.asp[...] 开头,并且浏览器中的 href 每次都以整个 url http://开头www.your.domain.de/[...]

编辑:href-values 的开头有点,所以用空白替换它们。

关于javascript - 添加基于 session URL 的事件导航类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56259820/

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