0

我遇到了一个问题,并且已经尝试解决了几个小时,但无法解决。我有一个侧边菜单栏,格式如下:

<ul class="collapse" id="menu">
    <li class="panel active">// class "active" should be added <a data-target="#dashboard-nav" class="accordion-toggle" data-toggle="collapse" data-parent="#menu" href="#">
            <i class="icon-dashboard"></i> Dashboard <span class="pull-right"><i class="icon-angle-left"></i></span>
        </a>

        <ul id="dashboard-nav" class="collapse in">// class "in" should be added
            <li class=""><a href="#"><i class="icon-angle-right"></i>Default Style</a>
            </li>
            <li class=""><a href="#"><i class="icon-angle-right"></i> Alternative Style</a>
            </li>
        </ul>
    </li>
    <li class="panel"> <a data-target="#registrations-nav" class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#menu" href="#">
            <i class="glyphicon glyphicon-user"></i> Registrations<span class="pull-right"><i class="icon-angle-left"></i></span>
        </a>

        <ul id="registrations-nav" class="collapse">
            <li><a href="#"><i class="icon-plus-sign"></i> Create Registration</a>
            </li>
            <li class="active"><a href="#"><i class="icon-list"></i> List Registration</a>
            </li>
            <li><a href="#"><i class="icon-adn"></i> Manage Registration</a>
            </li>
        </ul>
    </li>
    <li class="panel"> <a data-target="#settings-nav" class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#menu" href="#">
            <i class="icon-wrench"></i> Settings <span class="pull-right"><i class="icon-angle-left"></i> </span>
        </a>

        <ul id="settings-nav" class="collapse in">
            <li class="active"><a href="/ssw/index.php/admin/service/create"><i class="icon-leaf"></i> Services</a>
            </li>
            <li class=""><a href="#"><i class="icon-angle-right"></i> Sites</a>
            </li>
            <li class=""><a href="#"><i class="icon-angle-right"></i> Service Points</a>
            </li>
        </ul>
    </li>
</ul>

一旦我单击<li class="panel">“活动”类的任何项目,应将其添加为“活动”,<li class="panel active">并在下面添加“在”类中, 如果我无法解释清楚'<ul>, 请告诉我。<li class="panel"> ... <ul id="dashboard-nav" class="collapse in">

提前致谢

4

2 回答 2

0

小提琴演示

$('li.panel').click(function () {
    $('li.panel').removeClass('active');//remove active class from all li with class panel
    $('li.panel').children('ul').removeClass('in');//remove in class
    $(this).addClass('active'); // add class active to current li
    $(this).children('ul').addClass('in'); //add in class to the children ul
});

参考

.addClass()

.removeClass()

。孩子们()

这个关键字

于 2013-10-27T08:40:18.237 回答
0

我为它制作了一个javascript解决方案,如下所示:-

        window.onload=start;
        function start(){
            var list = document.getElementById("menu").childNodes;
            for(i=0;i<list.length;i++){
                list[i].onclick=clicked;
            }
        }
        function clicked(){
            var input = this;
            input.className = "panel active"
            var child = input.getElementsByTagName("ul")[0];
            child.className = "collaspe in"
        }
于 2013-10-27T09:06:26.043 回答