JS实现导航菜单点击高亮显示状态

2016-03-05   点击:   发布者:南京互诺科技
实现代码:

 

<script type="text/javascript" src="/js/jquery.min.js"></script>

<style>

.menu { padding:0; margin:0; list-style-type:none;}

.menu li { background:#FFD1A4; margin-right:1px; float:left; color:#fff; }

.menu li a { display:block; width:80px; text-align:center; height:32px; line-height:32px; color:#fff; font-size:13px; text-decoration:none;}

 

.cur{ background:#D96C00; font-weight:bold;}

</style>

 

<ul class="menu" id="menu">

  <li><a href="demo.html">首页</a></li>

  <li><a href="te1.html">PHPCMS</a></li>

  <li><a href="te2.html">DEDECMS</a></li>

</ul>

 

<script type="text/javascript">

  var urlstr = location.href;

  //alert((urlstr + '/').indexOf($(this).attr('href')));

  var urlstatus=false;

  $("#menu a").each(function () {

    if ((urlstr + '/').indexOf($(this).attr('href')) > -1&&$(this).attr('href')!='') {

      $(this).addClass('cur'); urlstatus = true;

    } else {

      $(this).removeClass('cur');

    }

  });

  if (!urlstatus) {$("#menu a").eq(0).addClass('cur'); }

</script>

window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"1","bdSize":"16"},"share":{},"image":{"viewList":["qzone","tsina","tqq","renren","weixin"],"viewText":"分享到:","viewSize":"16"},"selectShare":{"bdContainerClass":null,"bdSelectMiniList":["qzone","tsina","tqq","renren","weixin"]}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];

相关阅读