zoukankan      html  css  js  c++  java
  • 用jquery获取当前页面连接加css

    js代码

    /*nav a active*/
        $('nav ul li a').each(function(){
            if($(this)[0].href==String(window.location))
                $(this).addClass('active');
         });

    html代码

     1  <nav>
     2                   <ul>
     3                                                                <li>
     4                          <a href="http://localhost/myyiqicms/allcategory.php" title="环境类型" id="5">环境类型</a>
     5                      </li>
     6                                           <li>
     7                          <a href="http://localhost/myyiqicms/allproduct.php" title="所有产品" id="6">所有产品</a>
     8                      </li>
     9                                           <li>
    10                          <a href="http://localhost/myyiqicms/article/about.html" title="公司历程" id="2">公司历程</a>
    11                      </li>
    12                                           <li>
    13                          <a href="http://localhost/myyiqicms/category.php?name=zl.html" title="标准文献" id="15">标准文献</a>
    14                      </li>
    15                                           <li>
    16                          <a href="http://localhost/myyiqicms/comment.php" title="联系购买" id="4">联系购买</a>
    17                      </li>
    18                                        </ul>
    19                </nav>

    工作原理:

      判断当前浏览器的链接是否与标签中的链接相等,如相等则加上一个class:active,这样变能识别当前页是哪个导航标签了

    if you don't try,you will never know!
  • 相关阅读:
    docker基本指令
    Process API
    Go的Context用法
    golang的可空类型和零值
    动态编程(DynamicObject、ExpandoObject)
    git clean
    SQL Server Join
    公用表表达式 Common Table Expression
    ubuntu安装mysql
    asp.net core-使用Nlog和log4net
  • 原文地址:https://www.cnblogs.com/leeten/p/3447374.html
Copyright © 2011-2022 走看看