使用JQuery在加载新页面时保持活动的子导航打开 [英] Use JQuery to keep active sub-navigation open when loading a new page
问题描述
我已经建立了一个折叠和放大的侧边栏导航单击导航标题时展开。一切都很好。但是,如果我展开/打开其中一个导航组并单击以转到页面,则当新页面加载所有导航组时,将再次关闭。我很想找到主动导航组保持开放的方法。
I have built a sidebar navigation that collapses & expands when the nav titles are clicked. this all works great. however, if i expand / open one of the nav groups and click to go to a page, when the new page loads all the nav groups start out closed again. I would love to find a way for the active nav group to stay open.
这是我用于崩溃/扩展的内容:
(它是目前已设置,以便一次只能打开一个导航组。)
Here is what I've used for the collapse / expand: (it's currently set up so that only one of the nav groups will be open at a time)
/* Collapse and Expand */
$(".slideTitle").click(function() {
$(".indexListOpen").removeClass("indexListOpen").addClass("indexList");
$(this).next().toggleClass("indexList").toggleClass("indexListOpen");
});
这是我试图用来在新页面加载时保持当前导航组打开的内容:
And this is what I was trying to use to keep the current nav group open when the new page loads:
/* keep current nav group open */
var path = location.pathname;
$('.indexListOpen a[@href$="' + path + '"]').addClass("selected");
$(".selected").parent().parent().removeClass("indexList").addClass("indexListOpen");
不工作......所以我确定我做错了很多。
我正在处理的页面位于instarservices.com/commercial
Not working ... so I'm sure I'm doing plenty wrong. The page I am working on is located at instarservices.com/commercial
任何帮助表示赞赏!!!
Any help is appreciated!!!
推荐答案
正如dcneiner所说,在最新版本的jQuery中不推荐使用 @
。但看起来你的目标是 indexListOpen
在新页面加载时不存在。因此,要么删除它,要么将其更改为 indexList
,它应该可以工作
As dcneiner said the @
has been deprecated in the latest version of jQuery. But it looks like you are targeting a indexListOpen
that doesn't exist on a fresh page load. So either remove that or change it to indexList
and it should work
$('a[href$="' + path + '"]').addClass("selected");
或
$('.indexList a[href$="' + path + '"]').addClass("selected");
这篇关于使用JQuery在加载新页面时保持活动的子导航打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!