Bootstrap 折叠面板/折叠

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

我的Bootstrap accordian是行为喜怒无常!我已经创建了三个面板显示在一个列网格中,但第二和第三折叠菜单关闭错误的菜单(例如,单击/打开menu 2,然后单击/打开menu 3将关闭menu 2之前打开menu 3)。
知道为什么吗?

<div class="row">
  <div class="col-sm-6 col-md-4">
    <div class="panel-group">
      <div class="panel panel-default">
        <a class="panel-default" data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
        <div class="panel-heading">
          <h4 class="panel-title">
          My Story
          </h4>
        </div>
        </a>
        <div id="collapseOne" class="panel-collapse collapse">
          <div class="panel-body">
          Content
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="col-sm-6 col-md-4">
    <div class="panel-group" id="accordion">
      <div class="panel panel-default">
        <a class="panel-default" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">
        <div class="panel-heading">
          <h4 class="panel-title">
          My Skills
          </h4>
        </div>
        </a>                            
        <div id="collapseTwo" class="panel-collapse collapse in">
          <div class="panel-body">
          Content
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="col-sm-6 col-md-4">
    <div class="panel-group" id="accordion">
      <div class="panel panel-default">
        <a class="panel-default" data-toggle="collapse" data-parent="#accordion" href="#collapseThree">
        <div class="panel-heading">
          <h4 class="panel-title">
          My Ambition
          </h4>
        </div>
        </a>                            
        <div id="collapseThree" class="panel-collapse collapse">
          <div class="panel-body">
          content
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
eqoofvh9

eqoofvh91#

您需要对 accordion 进行编号,即 accordion 1 accordion 2 accordion 3

<div class="row">
    <div class="col-sm-6 col-md-4">
        <div class="panel-group">
            <div class="panel panel-default">
                <a class="panel-default" data-toggle="collapse" data-parent="#accordion1" href="#collapseOne">
                <div class="panel-heading">
                    <h4 class="panel-title">
                    My Story
                    </h4>
                </div>
                </a>
                <div id="collapseOne" class="panel-collapse collapse">
                    <div class="panel-body">
                    Content
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-sm-6 col-md-4">
        <div class="panel-group" id="accordion">
            <div class="panel panel-default">
                <a class="panel-default" data-toggle="collapse" data-parent="#accordion2" href="#collapseTwo">
                <div class="panel-heading">
                    <h4 class="panel-title">
                    My Skills
                    </h4>
                </div>
                </a>                            
                <div id="collapseTwo" class="panel-collapse collapse in">
                    <div class="panel-body">
                    Content
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-sm-6 col-md-4">
        <div class="panel-group" id="accordion">
            <div class="panel panel-default">
                <a class="panel-default" data-toggle="collapse" data-parent="#accordion3" href="#collapseThree">
                <div class="panel-heading">
                    <h4 class="panel-title">
                    My Ambition
                    </h4>
                </div>
                </a>                            
                <div id="collapseThree" class="panel-collapse collapse">
                    <div class="panel-body">
                    content
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

相关问题