使用bootstrap通用导航栏在php中显示活动链接

问题描述 投票:0回答:1

我正在创建一个php和bootstrap 4.我包含一个通用导航栏,并用<?php include 'filename.php'?>调用它。如何在每个页面上显示活动链接,例如,如果它在index.html,主页按钮或链接上将突出显示。

php bootstrap-4
1个回答
0
投票

您可以使用javascript显示当前活动的网址。

<script type="text/javascript">
    $(document).ready(function () {
        var url = window.location;
        $('ul.nav a[href="'+ url +'"]').parent().addClass('active');
        $('ul.nav a').filter(function() {
             return this.href == url;
        }).parent().addClass('active');
    });
</script>
© www.soinside.com 2019 - 2024. All rights reserved.