帝国cms灵动标签+JS实现【当前栏目高亮】,适用于任意页面

[ 帝国cms教程   // 2014-03-12  ]
87

此方法简单,适用于多种页面(首页、封面模板、列表模板、内容模板、自定义页面、自定义列表)
【自定义页面:head.html】代码:

<div>
<div>
  <ul id="nav">
    <li><a href="[!--news.url--]" title="首页" target="_self" id="home">首 页</a><href="http://www.softhome.cc/li>
    [e:loop={'select classid,classname,classpath from [!db.pre!]enewsclass where bclassid=0 and showclass=0 order by myorder',0,24,0}]
    <li><a id="cid<?=$bqr[classid]?>" href="<?=$public_r[newsurl]?><?=$bqr[classpath]?>" target="_self" ><?=$bqr[classname]?></a><href="http://www.softhome.cc/li>
    [/e:loop] 
    <!--<li><a href="http://www.baidu.com/a/" target="_self" id="cid1">A栏目</a><href="http://www.softhome.cc/li>-->
  </ul>
</div>
</div>
<!--当是在首页的时候,id=“home”的li高亮显示,也就是首页高亮-->
<script type="text/javascript">
if(document.URL=="http://www.你网站域名.com/"||document.URL=="http://www.你网站域名.com/index.html"){document.getElementById("home").className="chover";}
</script>
<!--end of header-->

【封面、列表、内容或自定义页面】代码:

<!--#include virtual="/head.html"-->
<script type="text/javascript">
var myid = document.getElementById('cid[!--self.classid--]');
myid.className = 'chover';
</script>

【CSS样式表】

<style>
.nav li a:hover,.chover{ background:#DC261C; color:#FFF;}
</style>