亲爱的朋友和程序员。
以下是我的代码的一部分。实际上,它是我的侧面菜单的一部分。我的代码问题是许多Bootstrap用户遇到的常见问题。单击后,我只希望显示我的可折叠项目之一,而其他先前打开的项目则被关闭。 提前致谢。
<ul>
<li class="link">
<a href="index.php">
<span class="fas fa-home" aria-hidden="true"></span>
<span class="d-none d-sm-inline">Home</span>
</a>
</li>
<li class="link">
<a href="#collapse-post" data-toggle="collapse" aria-expanded="false" aria-controls="collapse-post">
<span class="fas fa-paper-plane" aria-hidden="true"></span>
<span class="d-none d-sm-inline">Operation</span>
</a>
<ul class="collapse collapse-li-border" id="collapse-post">
<li><a href="#">Delete</a></li>
<li><a href="#">Create</a></li>
</ul>
</li>
<li class="link">
<a href="#collapse-edari" data-toggle="collapse" aria-expanded="false" aria-controls="collapse-edari">
<span class="fas fa-bullseye" aria-hidden="true"></span>
<span>Office</span>
</a>
<ul class="collapse collapse-li-border" id="collapse-edari">
<li><a href="#">Word</a></li>
<li><a href="#">Access</a></li>
<li><a href="#">Powerpoint</a></li>
</ul>
</li>
</ul>
答案 0 :(得分:1)
所以..在您的示例中,您应该更仔细地遵循dropdown component of bootstrap的文档。在这些情况下,折叠组件未完全使用。我对您的代码进行了一些更改,但是您需要针对具体情况进行调整。
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<ul>
<li class="link">
<a href="index.php">
<span class="fas fa-home" aria-hidden="true"></span>
<span>Home</span>
</a>
</li>
<li class="link">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false" aria-haspopup="true">
<span class="fas fa-paper-plane" aria-hidden="true"></span>
<span>Operation</span>
</a>
<ul class="dropdown-menu" id="collapse-post">
<li class="dropdown-item"><a href="#">Delete</a></li>
<li class="dropdown-item"><a href="#">Create</a></li>
</ul>
</li>
<li class="link">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false" aria-haspopup="true">
<span class="fas fa-bullseye" aria-hidden="true"></span>
<span>Office</span>
</a>
<ul class="dropdown-menu" id="collapse-edari">
<li class="dropdown-item"><a href="#">Word</a></li>
<li class="dropdown-item"><a href="#">Access</a></li>
<li class="dropdown-item"><a href="#">Powerpoint</a></li>
</ul>
</li>
</ul>