活动链接 jquery superfish
我有一个问题。 我使用 jquery superfish 菜单,其结构如下,
<div id="menu" class="ge-navigation-item">
<!-- navigation -->
<ul id="test" class="sf-menu sf-vertical sf-js-enabled sf-shadow">
<li><a href="index.html">Home</a></li>
<li><a href="#">About</a>
<ul>
<li><a href="index.html">Index</a></li>
<li><a href="#">Page</a>
<ul>
<li><a href="#">menu item</a></li>
<li><a href="#">menu item</a></li>
<li><a href="proef.html">menu item</a></li>
<li><a href="index.html">index</a></li>
<li><a href="#">menu item</a></li>
</ul>
</li>
<li><a href="page-fullwidth.php">Page - Full Width</a></li>
</ul>
</li>
<li><a href="showcase.php">Showcase</a></li>
</ul>
<!-- /navigation -->
</div>
我想要的是单击链接,菜单结构将可见
所以单击 index.html 将在所有带有 href index.html 的链接上设置一个链接 但是单击 proef.html 将在 href proef.html - 页面 - 关于上设置一个活动类
到目前为止,我已经尝试过此操作,但结果不佳
var path = window.location.toString().split("/")
path = path[path.length - 1]
//alert (path);
if (path)
$("#test a[href='" + path + "']").addClass("actief");
$("#test ul li:has(a) a[href='" + path +
"']").parent().parent().parent().addClass("actief");
I have a question.
I use jquery superfish menu with the following structure
<div id="menu" class="ge-navigation-item">
<!-- navigation -->
<ul id="test" class="sf-menu sf-vertical sf-js-enabled sf-shadow">
<li><a href="index.html">Home</a></li>
<li><a href="#">About</a>
<ul>
<li><a href="index.html">Index</a></li>
<li><a href="#">Page</a>
<ul>
<li><a href="#">menu item</a></li>
<li><a href="#">menu item</a></li>
<li><a href="proef.html">menu item</a></li>
<li><a href="index.html">index</a></li>
<li><a href="#">menu item</a></li>
</ul>
</li>
<li><a href="page-fullwidth.php">Page - Full Width</a></li>
</ul>
</li>
<li><a href="showcase.php">Showcase</a></li>
</ul>
<!-- /navigation -->
</div>
what I want is that clicking on a link the menu structure will be visible
So clicking on index.html will set a link on all links with href index.html
But clicking on proef.html will set an active class on href proef.html - Page - About
So far I have tried this but with bad results
var path = window.location.toString().split("/")
path = path[path.length - 1]
//alert (path);
if (path)
$("#test a[href='" + path + "']").addClass("actief");
$("#test ul li:has(a) a[href='" + path +
"']").parent().parent().parent().addClass("actief");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
欢迎来到 stackoverflow。试试这个:
这应该将该类应用于与当前 url 的最后一项匹配的任何链接。如果您正在寻找不同的行为,请详细说明!
更新
实际上,看起来您需要这样:
这会将类放在链上的每个
a
元素上。Welcome to stackoverflow. Try this:
That should appply the class to any link that matches the last item of the current url. If you were looking for a different behavior, please elaborate!
UPDATE
Actually, it looks like you need this:
That will put the class on every
a
element up the chain.我们做了类似的事情:
它似乎有效,但将鼠标悬停在菜单上时,菜单不保持当前位置。
=== 更新 ===
鼠标悬停在菜单上后,父 ul 似乎被重置为不显示
we did something like:
It seems to work but on mousing over the menu, the menu doesn't hold the current position.
=== update ===
It seems the parent ul is reset to not display after mousing over the menu