左侧多级菜单,高亮显示js

左侧多级菜单,如果本页面是当前栏目,则左侧菜单高亮显示

<ul class="nav navbar-stacked" id="navs">
{dede:channelartlist typeid='46,46'}

<li _id="#couse_1" class=""><a id="bb33" href="[field:typelink/]">[field:typename/]</a></li>

{/dede:channelartlist}
</ul>

<script type="text/javascript">
var myNav = document.getElementById("navs").getElementsByTagName("a");//获取nav ul下的a连接
for(var i=0;i<myNav.length;i++){
var links = myNav[i].getAttribute("href");//获取a里面的连接地址
//console.log(myNav[i]);
//<a id="bb" href="[field:typelink/]">[field:typename/]</a>
//console.log(classna);
var myURL = document.location.href;//url 连接地址
//http://st.com/a/ENGLISH/Responsibilities/gaest
if(myURL.indexOf(links) != -1){//duibi
var elem = myNav[i];
var paid = elem.parentElement;//获取父级元素
paid .className="active";//修改腹肌元素的class名
//console.log(paid);//<li></li>
//console.log(myNav[i]);//<a id="bb" href="[field:typelink/]">[field:typename/]</a>
// myNav[i].className="active_2";
}
}
</script>

上一篇:笔记-AndroidStudio开发环境的搭建


下一篇:SQL Timeout超时的处理方法