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

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

    I've placed this in each one of my content pages, changing the id of the nav item for each page (this uses JQuery selectors). So for this to work for you you'll need to give your list items an Id. I don't add the "active" class to the master page because all we need to do is highlight the appropriate one when the content loads.

    
    

    Note: if you're using ASP.NET controls instead of list items inside of your nav bar, they might be getting prefixed at runtime causing your javascript not to find the Id you think you're looking for.

提交回复
热议问题