比较 URL 和链接
我有以下 HTML:
<ul class="vertical_menu no_select">
<li class="edge_top"> </li>
<!-- Menu Items Here -->
<li class="not_selected"><a class="selection_link" href="index.htm">Home</a></li>
<li class="not_selected"><a class="selection_link" href="index.htm">Subitem 1</a></li>
<li class="not_selected"><a class="selection_link" href="index.htm">Subitem 2</a></li>
<!-- Menu Items End Here -->
<li class="edge_bottom"> </li>
</ul>
现在,具有类 "selection_link"
的链接需要具有 li
元素(其父元素)才能选择新的类 " "
如果当前 url
与锚标记内的 href
值匹配。我可以获得完整的 URL,但我不知道如何使用它来帮助查看,因为在不同的目录级别可能有多个具有相同名称的页面。
如果您能提供帮助,谢谢!我正在使用 jQuery 来完成这一切,所以请随时为我提供 jQuery 示例!
I have the following HTML:
<ul class="vertical_menu no_select">
<li class="edge_top"> </li>
<!-- Menu Items Here -->
<li class="not_selected"><a class="selection_link" href="index.htm">Home</a></li>
<li class="not_selected"><a class="selection_link" href="index.htm">Subitem 1</a></li>
<li class="not_selected"><a class="selection_link" href="index.htm">Subitem 2</a></li>
<!-- Menu Items End Here -->
<li class="edge_bottom"> </li>
</ul>
Now, the links with the class "selection_link"
need to have the li
element (their parent) to have a new class "selected"
if the current url
matches the href
value inside of the anchor tag. I can get the full URL but I don't know how to use that to help seeing as there could be more than one page with the same name at different directory levels.
Thanks if you can help! I'm using jQuery with all of this so feel free to provide me with jQuery examples!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看 jsFiddle。这应该可以解决问题:
Check out the jsFiddle. This should do the trick:
未经测试,但它应该让你开始。 substring 是因为路径名以“/”开头,您也可以将其放入 href 中
not tested, but it'll it should start you off. substring is because pathname starts with '/' you could just put that in your href's too
或者这个...
or this...