How to set navbar item as active when user selects it?

后端 未结 9 1286
耶瑟儿~
耶瑟儿~ 2021-02-05 18:45

I am a new ASP.NET Web Forms developer and trying to use Twitter Bootstrap with the Master Page. I am struggling with setting navbar item as active when user selects it. I creat

9条回答
  •  别那么骄傲
    2021-02-05 19:01

    Use this:

    
    
    $(document).ready(function () {
            var url = window.location;
            $('.navbar .nav').find('.active').removeClass('active');
            $('.navbar .nav li a').each(function () {
                if (this.href == url) {
                    $(this).parent().addClass('active');
                }
            }); 
        });
    

    Example: http://jsfiddle.net/yUdZx/3/

    And, in the "href" use "Page.ResolveUrl"

    ">Clients
    

    It's better...

提交回复
热议问题