我有我的菜單這裏:jQuery的匹配前綴window.location.pathname
<ul>
<li class="step-1"><a href="/why-build">Why Build</a></li>
<li class="step-2"><a href="/land">Land</a></li>
<li class="step-3"><a href="/builders">Builders</a></li>
</ul>
我嘗試添加「選擇」菜單項時,我該網頁(即/爲什麼建造)的類,或它的子頁面(即/ why-build/page1或/ why-build/page2等)。第一個李將是
<li class="step-1 selected"><a href="/why-build">Why Build</a></li>
所以基本上所有的url匹配pattern/why-build/*。我如何檢查window.location.pathname?對不起,我不擅長正則表達式。乾杯。
但不要我們需要做相反?當我們在page/why-build/page2上時,window.location.pathname =/why-build/page2。然後/爲什麼構建不匹配[href^='/ why-build/page2'],'selected'類無法添加。 – Alex
是的,我知道了。我用'.filter'重做了它。 – Barmar
非常感謝。它效果很好。 – Alex