jQuery:在链接点击之后,将类添加到li元素,并取消选择所有其他类 [英] jQuery: Adding class to the li element after the link is clicked, and deselecting all other classes
问题描述
我正在生成包含此类标签的菜单:
I am generating menu with such tags:
<div class="animatedtabs">
<ul>
{% for item in menu_items %}
<li><a href="{{ item.url }}" title="{{ item.name }}"><span>{{ item.name }}</span></a></li>
{% endfor %}
</ul>
</div>
我想做什么,我要添加class =selected到li,链接后被点击,并删除所有其他类=选择在其他li的...
What I want to do, I want to add class="selected" to li, after the link is clicked, and to remove all other class="selected" on other li's...
另外我不知道,如何显示菜单的方式,所以第一个项目默认情况下选择...但是当另一个链接被点击时,class =selected被切换
Also I wonder, how to show menu in the way, so the first item is selected by default... But then when another linked is clicked, then class="selected" is toggled
推荐答案
有关于Django中导航菜单的相关问题:
在django中导航
There is a related question about navigation menus in Django: Navigation in django
此答案有一个很好的例子,使用模板标签将类添加到 li
元素。
在django中导航
This answer has a good example of using a template tag for adding the classes to the li
elements.
Navigation in django
这篇关于jQuery:在链接点击之后,将类添加到li元素,并取消选择所有其他类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!