if href=url 更改菜单上活动状态的类
我试图用 jquery 创建一个活动状态...
这是我不起作用的代码...
<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function() {
jQuery('ul#menuHov a[href$="' + window.location.pathname + '"]').addClass("menuHov");
});
</script>
以及菜单...
<ul id="menuHov">
<li style="width:128px"><a href="" ><span>SHOP<br/>SHOP</span></a></li>
<li style="width:193px"><a href="/collections" ><span>COLLECTIONS<br/>COLLECTIONS</span></a></li>
<li style="width:147px"><a href="/about-local-celebrity"><span>ABOUT<br/>ABOUT</span></a></li>
<li style="width:186px"><a href="/stockists" ><span>STOCKISTS<br/>STOCKISTS</span></a></li>
<li style="width:146px"><a href="/press" ><span>PRESS<br/>PRESS</span></a></li>
<li style="width:128px"><a href="/category/blog" ><span>BLOG<br/>BLOG</span></a></li>
<li style="width:70px"><a href="/contact" ><span>CONTACT<br/>CONTACT</span></a></li>
</ul>
以及我想要作为活动状态的类...
.menuHov {color:#fae349}
im trying to make an active state with jquery...
heres my code that isn't working..
<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function() {
jQuery('ul#menuHov a[href$="' + window.location.pathname + '"]').addClass("menuHov");
});
</script>
and the menu...
<ul id="menuHov">
<li style="width:128px"><a href="" ><span>SHOP<br/>SHOP</span></a></li>
<li style="width:193px"><a href="/collections" ><span>COLLECTIONS<br/>COLLECTIONS</span></a></li>
<li style="width:147px"><a href="/about-local-celebrity"><span>ABOUT<br/>ABOUT</span></a></li>
<li style="width:186px"><a href="/stockists" ><span>STOCKISTS<br/>STOCKISTS</span></a></li>
<li style="width:146px"><a href="/press" ><span>PRESS<br/>PRESS</span></a></li>
<li style="width:128px"><a href="/category/blog" ><span>BLOG<br/>BLOG</span></a></li>
<li style="width:70px"><a href="/contact" ><span>CONTACT<br/>CONTACT</span></a></li>
</ul>
and the class i want as active state...
.menuHov {color:#fae349}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它对我来说效果很好:
http://jsfiddle.net/maniator/JYc8g/ (如果您没有看到它立即起作用)
确保路径正确,使用 firebug 或 chrome 控制台检查您想要
更新 的页面上的
window.location.pathname
strong>似乎是一个 css 问题,将 user.css 的第 95 行更改为:
it works fine for me:
http://jsfiddle.net/maniator/JYc8g/ (click run if u don't see it work right away)
make sure the path is correct, use the firebug or chrome console to check what
window.location.pathname
is on the page you wantUPDATE
seems to be a css issue change line 95 of user.css to: