Make clicked tab active in Bootstrap

后端 未结 10 635
傲寒
傲寒 2021-01-31 09:02

I am using Django and integrated Bootstrap with Django. Here is my HTML code for the navigation bar:

10条回答
  •  礼貌的吻别
    2021-01-31 09:43

    This solution didn't work when the href attribute of your links will be different from href="#". Why ? Simply because each click on a link triggers a request to the server. In your JS code, you add the method preventDefault() in order to avoid this basic behavior, but I think that not really your objective for this purpose, isn't it ?

    To handle this kind of feature you can update your template code by adding something like this :

    base.html

    
    

    views.py

    def your_view(request):
        ...
        return render(request, 'yourtemplate.html', {'nbar': 'home'})
    

    With this way, you don't have to manage this feature with javascript.

提交回复
热议问题