我知道这是一个简单的jQuery任务,我已经完成了一百万次,但我似乎无法添加一个"活跃的"根据页面URL对下面的菜单项进行分类。这是使用http://localhost:8888/的问题吗?有2个索引页面,1个php 1 html是一个问题吗?我如何定位subnav?
<nav class="header-menu menu">
<ul>
<li class="menu-item-has-children">
<a href="/expertise">
<span class="nav-text">Expertise</span>
<span class="icon-down-arrow-small "></span>
</a>
<ul class="sub-menu">
<li><a href="">Meet our Team</a></li>
<li><a href="">Contact Us</a></li>
<li><a href="">Our Process</a></li>
</ul>
</li>
<li class="menu-item-has-children">
<a href="/projects">
<span class="nav-text">Projects</span>
<span class="icon-down-arrow-small "></span>
</a>
<ul class="sub-menu">
<li><a href="">Meet our Team</a></li>
<li><a href="">Contact Us</a></li>
<li><a href="">Our Process</a></li>
<li><a href="">Our Process</a></li>
<li><a href="">Our Process</a></li>
</ul>
</li>
<li>
<a href="/about">
<span class="nav-text">About</span>
<span class="icon-down-arrow-small "></span>
</a>
</li>
<li>
<a href="#">
<span class="nav-text">Insights</span>
<span class="icon-down-arrow-small "></span>
</a>
</li>
<li>
<a href="#">
<span class="nav-text">Careers</span>
<span class="icon-down-arrow-small "></span>
</a>
</li>
</ul>
</nav>
$(function() {
var url = location.origin + location.pathname;
$('nav a[href^="' + url + '"]')
.closest('li')
.addClass('active');
});