There is a navigation bar, and I want to add a class = 'on' attribute when this navigation is activated
If you click on the second navigation item, add this class to the second item
{% for nav in NAV %}
<li>nav</li>
{% end for %}
for example
<li class="on">第一项</li>
<li>第二项</li>
<li>第三项</li>
How to implement this?
You have nothing to do with django.
This is a problem with the front-end page. For example:
You load all the navigation to the front-end page at once, and then you need to open the current menu based on clicks, and then turn off the effects of other menus, right?
If I understand correctly, this is a front-end problem
1. Bootstrap or UIKit all support this effect;
2. Write the navigation style yourself, for example, name it
active
, and then give you the clicked object in jQuery$(this).addClass('active')
, this is an idea;