Make Twitter Bootstrap navbar link active

前端 未结 9 957
情深已故
情深已故 2020-11-30 21:33

What\'s the standard way to make the active link in a Twitter Bootstrap navbar bolded? It\'s clear that a link gains the active appearance by gaining the \"active\" class. F

相关标签:
9条回答
  • 2020-11-30 22:11

    Chris Moutray your answer helped me a lot in the develop of my software (i'm using ZendFramework). I wrote this view helper:

    <?php
    
    class Zend_View_Helper_ActiveOrNot {
    
        function activeOrNot ( $requestUri ) { 
    
            $current_file_name = basename($_SERVER['REQUEST_URI'], ".php");
    
            if ($current_file_name == $requestUri)
    
                echo 'class="active"';
    
        }   
    
    }
    

    In this case i call this helper in the view thus:

    <?php $this -> activeOrNot ( "public" );
    

    Thanks U!!

    0 讨论(0)
  • 2020-11-30 22:13

    Just put the below code into "head" section.

    <script type="text/javascript">
    $(document).ready(function () {
    $("li a[href='" + location.href.substring(location.href.lastIndexOf("/") + 1, 255) + "']").addClass("active");
    });
    </script>
    

    obviously don't forget your call to jquery.js before.

    And your:

    <style>
    .active{something...}
    </style>
    
    0 讨论(0)
  • 2020-11-30 22:16

    Add the following script at the bottom of the page:

    <script>
        $(document).ready(function() {
            var url = this.location.pathname;
            var filename = url.substring(url.lastIndexOf('/')+1);
            $('a[href="' + filename + '"]').parent().addClass('active');
        });
    </script>
    
    0 讨论(0)
提交回复
热议问题