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

后端 未结 9 1288
耶瑟儿~
耶瑟儿~ 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:12

    var windowUrl = window.location.href.toLowerCase();
    //var windowUrl = window.location.href.toLowerCase().split('.')[0];
    setTimeout(function () {
        var windowUrl = window.location.href.toLowerCase();
        $('#nav li').removeClass('active');
        $('#nav li').each(function (index) {
            pageUrl = $(this).find('a').attr('href');
            if (windowUrl.indexOf(pageUrl) > -1) {
                $(this).addClass('active');
            }
        });
    }, 10);
    

提交回复
热议问题