如何修改我的代码,以便我的列表以手风琴的形式运行

时间:2016-05-23 17:11:32

标签: javascript jquery twitter-bootstrap accordion collapse

我仍然知道引导程序。如何修改我的代码,以便单击可折叠字段将折叠<li>标记(accordion)中的其他字段。我知道您必须使用data-parent值,但是,在进行实验时,我无法让它崩溃。

示例:点击“用户”链接后,关闭“学习单元”和“注册”部分

<li>
    <a class="admin collapsed sidebar-parent" data-toggle="collapse" href="#sidebar-admin" style="border-top: none;"><i class="fa fa-wrench" style="margin-right: 17px; margin-left: 1px;"></i>Admin</a>
    <ul id="sidebar-admin" class="nav collapse">
        <li>
            <!-- Users -->
            <a class="users collapsed sidebar-subparent" data-toggle="collapse" href="#sidebar-users"> &nbsp; &nbsp;<i class="fa fa-user" style="margin-right: 15px; margin-left: 2px;"></i>Users</a>
            <ul id="sidebar-users" class="nav collapse">
                <li class="sidebar-element">
                    <a href="@Url.Content("~/Admin/Users")"> &nbsp; &nbsp; &nbsp; &nbsp;<i class="fa fa-search" style="margin-right: 8px;"></i> Search Users</a>
                </li>
                <li class="sidebar-element">
                    <a href="@Url.Content("~/Admin/NewUser")"> &nbsp; &nbsp; &nbsp; &nbsp;<i class="fa fa-plus-circle" style="margin-right: 12px;"></i> Add Users</a>
                </li>
                <li class="sidebar-element">
                    <a href="@Url.Content("~/Admin/Roles")"> &nbsp; &nbsp; &nbsp; &nbsp;<i class="fa fa-users" style="margin-right: 10px; margin-left: -1px;"></i> Assign Roles</a>
                </li>
            </ul>

            <!-- Units -->
            <a class="unitsofstudy collapsed sidebar-subparent" data-toggle="collapse" href="#sidebar-units"> &nbsp; &nbsp;<i class="fa fa-university" style="margin-right: 12px;"></i>Units of Study</a>
            <ul id="sidebar-units" class="nav collapse">
                <li class="sidebar-element">
                    <a href="@Url.Content("~/Admin/Units")"> &nbsp; &nbsp; &nbsp; &nbsp;<i class="fa fa-search" style="margin-right: 8px;"></i> Search Units</a>
                </li>
                <li class="sidebar-element">
                    <a href="@Url.Content("~/Admin/NewOfferedUnit")"> &nbsp; &nbsp; &nbsp; &nbsp;<i class="fa fa-plus-circle" style="margin-right: 10px;"></i> Register Units</a>
                </li>
                <li class="sidebar-element">
                    <a href="@Url.Content("~/Admin/NewUnit")"> &nbsp; &nbsp; &nbsp; &nbsp;<i class="fa fa-plus-circle" style="margin-right: 10px;"></i> Register Semester</a>
                </li>
                <li class="sidebar-element">
                    <a href="@Url.Content("~/Admin/NewSemester")"> &nbsp; &nbsp; &nbsp; &nbsp;<i class="fa fa-plus-circle" style="margin-right: 10px;"></i> Offer Units</a>
                </li>
            </ul>

            <!-- Enrolments -->
            <a class="enrolments collapsed sidebar-subparent" data-toggle="collapse" href="#sidebar-admenrolments"> &nbsp; &nbsp;<i class="fa fa-graduation-cap" style="margin-right: 12px; margin-left: -2px;"></i>Enrolments</a>
            <ul id="sidebar-admenrolments" class="nav collapse">
                <li class="sidebar-element">
                    <a href="@Url.Content("~/Admin/Enrolments")"> &nbsp; &nbsp; &nbsp; &nbsp;<i class="fa fa-search" style="margin-right: 8px;"></i> Search Enrolments</a>
                </li>
                <li class="sidebar-element">
                    <a href="@Url.Content("~/Admin/NewEnrolment")"> &nbsp; &nbsp; &nbsp; &nbsp;<i class="fa fa-plus-circle" style="margin-right: 10px;"></i> Enrol Students</a>
                </li>
            </ul>
        </li>
    </ul>
</li>

1 个答案:

答案 0 :(得分:1)

手风琴行为取决于panel类(http://getbootstrap.com/javascript/#collapse-options)。因此,父#sidebar-admin的直系孩子必须是.panel ..

http://www.codeply.com/go/Zq1utEY3dV

<ul id="sidebar-admin" class="nav collapse">
        <li class="panel">
            <a class="users collapsed sidebar-subparent" data-toggle="collapse" data-parent="#sidebar-admin" href="#sidebar-users"> &nbsp; &nbsp;<i class="fa fa-user" style="margin-right: 15px; margin-left: 2px;"></i>Users</a>
            <ul id="sidebar-users" class="nav collapse">
                <li class="sidebar-element">
                   ...