可折叠按钮 - Bootstrap 3.3.4

时间:2016-10-08 12:41:30

标签: javascript css twitter-bootstrap-3

我正在使用bootstrap可折叠按钮组。我希望一次只能看到一个单独的组框。我在js中创建了一个函数来删除“in”类并更改aria-expanded语句,但我认为这是无用的,因为人们正在使用data-parent =“#myGroup”。

显然,data-parent =“#myGroup”不适用于我。

我尝试在单个元素和两个按钮和折叠组上使用data-parent,但仍然无法使其工作。

在这个小提琴中你可以看到可以显示多个组。当我按下按钮时,我希望其他人隐藏。

 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<p>
  <button id="a" class="btn btn-primary" type="button" data-toggle="collapse" data-target="#AA" aria-expanded="false" aria-controls="AA" data-parent="#myGroup">
  A
  </button>

  <button id="b" class="btn btn-primary" type="button" data-toggle="collapse" data-target="#BB" aria-expanded="false" aria-controls="BB" data-parent="#myGroup">
    B
  </button>

    <button id="c" class="btn btn-primary" type="button" data-toggle="collapse" data-target="#CC" aria-expanded="false" aria-controls="CC" data-parent="#myGroup">
    C
  </button>

      <button id="d" class="btn btn-primary" type="button" data-toggle="collapse" data-target="#DD" aria-expanded="false" aria-controls="DD" data-parent="#myGroup">
    D
  </button> 
</p>


<div class="collapse" id="AA" data-parent="#myGroup">
  <div class="card card-block">
   bla bla bla
  </div>
</div>


<div class="collapse" id="BB" data-parent="#myGroup">
  <div class="card card-block">
bla bla bla
  </div>
</div>




<div class="collapse" id="CC" data-parent="#myGroup">
  <div class="card card-block">
    bla bla bla
  </div>
  </div>



<div class="collapse" id="DD" data-parent="#myGroup">
  <div class="card card-block">
    bla bla bla
      </div>
    </div>

</body>
</html>

1 个答案:

答案 0 :(得分:1)

发布自:关于重复问题的ambs:CSS Collapsible groups - Bootstrap

&#13;
&#13;
 
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<body>
<div id="container">
  <div class="panel">
    <p>
        <button id="a" class="btn btn-primary" data-toggle="collapse" data-target="#AA" data-parent="#container">
          A
        </button>
        <button id="b" class="btn btn-primary" data-toggle="collapse" data-target="#BB" data-parent="#container">
          B
        </button>
    </p>

    <div class="collapse" id="AA">
      <div class="card card-block">
          bla bla bla A
      </div>
    </div>

    <div class="collapse" id="BB">
      <div class="card card-block">
         bla bla bla B
      </div>
    </div>
  </div>
</div>
</body>
&#13;
&#13;
&#13;