如何在单击其2级菜单时将侧边栏菜单1级菜单设置为活动状态? [英] How do I set my sidebar menu level 1 menu to active upon clicking its level 2 menu?
问题描述
所以基本上我有一个侧边栏菜单映射像这样
(请注意,这不是树视图,而是使用SB-Admin2的侧边栏菜单):
*父母
列表
详情
*学生
列表
详情
等级
Creadentials
家长/学生(1级菜单)
列表/详情/等级/证书(2级菜单)
当我点击2级菜单时,我想在1级菜单上添加课程。
非常感谢您的帮助。
:)
< li id =level2Listonclick =markLevel1();> ;列表< / li>
function markLevel1(){
(#level2List)。parent.parent.addClass(yourClass)
}
此解决方案假设以下菜单结构和jQuery的使用
< ul>
< li>等级1
< ul>
< li>等级2< / li>
< / ul>
< / li>
< / ul>
这可以通过使用class而不是id来改进或推广,使用
(this)在函数内和/或命名父级,因此你可以使用jQuery中的.closest(selector)函数。
调整到您的特定菜单结构
So basically I have a sidebar menu mapped like this
(Please be informed that this is not a treeview but rather a sidebar menu using SB-Admin2):
*Parents List Details *Students List Details Grades Creadentials
Parents / Students (Level 1 Menu)
List / Details / Grades / Credentials (Level 2 Menu)
I wanted to add class on Level 1 Menu when I click on Level 2 Menu.
Your help would be greatly appreciated.
:)
<li id="level2List" onclick="markLevel1();">List</li>
function markLevel1() {
("#level2List").parent.parent.addClass("yourClass") }
This solution assumes the following menu structure and the use of jQuery
<ul> <li>level 1 <ul> <li>level 2</li> </ul> </li> </ul>
This could be improved or generalized by using class instead of id, use of
(this) within the function and/or naming the parent so you could use .closest("selector") function from jQuery.
Adjust to your particular menu stucture
这篇关于如何在单击其2级菜单时将侧边栏菜单1级菜单设置为活动状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!