如何激活菜单项类 [英] How do I give menu item class active
本文介绍了如何激活菜单项类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的朋友们,
我有html:
Dear friends,
I have html:
<div class="w-nav-item-h" id="mydiv">
<a class="w-nav-anchor level_1" href="/english/about-us/word-from-the-chairman">
<span class="w-nav-title">Word from the Chairman</span>
</a>
</div>
我想给divmydiv等级活跃 根据带有这个java脚本的页面网址:
And I want to give class "active" to the div "mydiv" according to the the page url with this java script cod :
<script type="text/javascript">
$(function () {
$("#mydiv").removeClass('active');
var lnk = window.location.href;
lnk = lnk.toLowerCase();
$("#mydiv a").each(function (index) {
if (lnk.indexOf($(this).html().trim().toLowerCase().replace(" ", "-")) != -1) {
$(this).parent().addClass('active');
}
});
});
</script>
但它无法正常工作:( ..请帮我找一个好的解决方案???
but it is not working :( .. Please help me to find a good solution ???
推荐答案
(function(){
(function () {
(#mydiv)。removeClass('active');
var lnk = window.location.href;
lnk = lnk.toLowerCase();
("#mydiv").removeClass('active'); var lnk = window.location.href; lnk = lnk.toLowerCase();
(#mydiv a)。each(function(index){
if(lnk.indexOf(
("#mydiv a").each(function (index) { if (lnk.indexOf(
这篇关于如何激活菜单项类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文