如何在twitter bootstrap 4中显示一个可折叠的项目?

ghhkc1vu  于 2022-12-07  发布在  Bootstrap
关注(0)|答案(1)|浏览(143)

亲爱的程序员朋友们。
下面是我的代码的一部分。实际上,它是我的副菜单的一部分。我的代码问题是很多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>
ffx8fchx

ffx8fchx1#

因此,在您的示例中,您应该更仔细地遵循dropdown component of bootstrap的文档。Collapse组件并不完全用于这些情况。我在您的代码中做了一些更改,但您需要针对您的特定情况对其进行调整。

<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>

相关问题