首页 > CMS建站 > Z-Blog > 正文

z-blog让导航突出显示当前页链接条目

2020-02-16 10:43:24
字体:
来源:转载
供稿:网友
关键字描述:链接 当前 显示 导航 突出 " < .attr this 代码

z-blog让导航突出显示当前页链接条目:

我们的大致思路是这样的,首先用js给导航部分中当前链接项加个区分的ID,如<li id=“current”>首页</li>,然后再用CSS定义就完成了。

  • setp1 :加入js(jQuery代码),如下

    原先功能简单的代码

    <script type="text/javascript">$(document).ready(function(){$("#menu ul>li").each(function() {  //我们假设导航部分的ID为menu,结构是<div id="menu"><ul><li>...    if ($(this).find("a").attr("href")==document.URL){    $(this).attr("id","current")  //给当前页的<li>加上id="current",如<li id="current">首页</li>    }});});</script>

    haphic将这一代码做了完善,此代码只支持 Z-Blog 模板.

    haphic 完善后的代码

    <script type="text/javascript">    $("#menu ul>li").each(function() {        if ($(this).find("a").attr("href").toLowerCase() !== str00.toLowerCase()){            if (document.URL.toLowerCase().indexOf($(this).find("a").attr("href").toLowerCase()) !== -1){                $(this).attr("id","current")            }        }else{            if ($(this).find("a").attr("href").toLowerCase() == document.URL.toLowerCase()){                $(this).attr("id","current")            }        }    });</script>
  • setp2 :定义CSS样式
    #menu ul li#current { background-color:#fff; color:#0B1316;}

  • 发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表

    图片精选