gpt4 book ai didi

javascript - 如何修改我的代码以便我的列表像 Accordion 一样运行

转载 作者:行者123 更新时间:2023-11-27 22:58:03 26 4
gpt4 key购买 nike

我仍在了解 Bootstrap 。如何修改我的代码,以便单击可折叠字段将折叠 <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>

最佳答案

Accordion 行为取决于 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">
...

关于javascript - 如何修改我的代码以便我的列表像 Accordion 一样运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37396809/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com