简体   繁体   English

导航活动类在服务器上不起作用

[英]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. 奇怪的是,该功能在我的本地PC上运行良好。 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');
        }
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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