Home > Web Front-end > HTML Tutorial > How to implement a navigation bar link to jump after clicking it, and add color to the corresponding link on the new page

How to implement a navigation bar link to jump after clicking it, and add color to the corresponding link on the new page

一个新手
Release: 2017-10-19 09:08:28
Original
7432 people have browsed it

html:

<p class="nav">
        <ul>
            <li class="active"><a href="a.html">aaa</a></li>
            <li><a href="b.html">bbb</a></li>
            <li><a href="c.html">ccc</a></li>
        </ul>
        
    </p>
Copy after login

jquery:

$(".nav li a").each(function (i) {
        var $me = $(this);
        var lochref = $.trim(window.location.href);
        var mehref = $.trim($me.get(0).href);
        if (lochref.indexOf(mehref) != -1) {
            $me.parent().addClass("active");
        } else {
            $me.parent().removeClass("active");
        }
    });
Copy after login

css:

.active{background-color:#ed0505;}
Copy after login

The above is the detailed content of How to implement a navigation bar link to jump after clicking it, and add color to the corresponding link on the new page. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template