简体   繁体   中英

Navigation active class not working on server

I developed a navigation bar. I just add an active class for links that highlight the current link. The strange thing is that the feature is working on my local pc perfectly. I just uploaded it to my server and check, but it's not working at all.

This is the uploaded site

This is the script that I used.

$(function () {
    var url = window.location;

    $('ul.active-link a[href="' + url + '"]').parent().addClass('active');


    $('ul.active-link a').filter(function () {
        return this.href == url;
    }).parent().addClass('active');
});
<script>
$(document).ready(function () {
    var location = window.location.href;
    $('#nav li a').each(function(){
        if(location.indexOf(this.href)>-1) {
           $(this).parent().addClass('active');
        }
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM