使用一个处理程序运行两个Bootstrap 3崩溃的问题

时间:2014-10-02 07:32:11

标签: jquery twitter-bootstrap twitter-bootstrap-3

请你看看this demo,让我知道如何只需点击一下就可以运行这两个崩溃,在A1或A2上无关紧要但是对于A1和A2折叠.panel-collapse

<div class="container">
<div class="row">
<div class="col-md-2 col-lg-2 col-sm-2 col-xs-2">
  <div class="panel-group" id="accordion">
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
          A 1
        </a>
      </h4>
    </div>
    <div id="collapseOne" class="panel-collapse collapse in">
      <div class="panel-body">
     A 1
      </div>
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">
          B 1
        </a>
      </h4>
    </div>
    <div id="collapseTwo" class="panel-collapse collapse">
      <div class="panel-body">
        B 1
      </div>
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a data-toggle="collapse" data-parent="#accordion" href="#collapseThree">
          C 1
        </a>
      </h4>
    </div>
    <div id="collapseThree" class="panel-collapse collapse">
      <div class="panel-body">
        C 1
      </div>
    </div>
  </div>
</div>
  </div>
<div class="col-md-2 col-lg-2 col-sm-2 col-xs-2">
 <div class="panel-group" id="accordion">
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
          A 2
        </a>
      </h4>
    </div>
    <div id="collapseOne" class="panel-collapse collapse in">
      <div class="panel-body">
     A 2
      </div>
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">
          B 2
        </a>
      </h4>
    </div>
    <div id="collapseTwo" class="panel-collapse collapse">
      <div class="panel-body">
        B 2
      </div>
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a data-toggle="collapse" data-parent="#accordion" href="#collapseThree">
          C 2
        </a>
      </h4>
    </div>
    <div id="collapseThree" class="panel-collapse collapse">
      <div class="panel-body">
        C 2
      </div>
    </div>
  </div>
</div> 

  </div>
</div>

由于

1 个答案:

答案 0 :(得分:3)

我认为您可以通过在数据父级和href标记中使用类而不是ID来实现此目的。

这是一个更新的小提琴:http://jsfiddle.net/Lj4Lqkkz/

顺便说一下,你的html有一些重复的ID。 ID应该是唯一的。您可能想要解决此问题,或者您可能会遇到其他一些问题。

<div class="container">
<div class="row">
<div class="col-md-2 col-lg-2 col-sm-2 col-xs-2">
  <div class="panel-group" id="accordion" class="accordion">
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a data-toggle="collapse" data-parent=".accordion" href=".collapseOne">
          A 1
        </a>
      </h4>
    </div>
    <div id="collapseOne" class="panel-collapse collapse in collapseOne">
      <div class="panel-body">
     A 1
      </div>
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a data-toggle="collapse" data-parent=".accordion" href=".collapseTwo">
          B 1
        </a>
      </h4>
    </div>
    <div id="collapseTwo" class="panel-collapse collapse collapseTwo">
      <div class="panel-body">
        B 1
      </div>
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a data-toggle="collapse" data-parent=".accordion" href=".collapseThree">
          C 1
        </a>
      </h4>
    </div>
    <div id="collapseThree" class="panel-collapse collapse collapseThree">
      <div class="panel-body">
        C 1
      </div>
    </div>
  </div>
</div>
  </div>
<div class="col-md-2 col-lg-2 col-sm-2 col-xs-2">
 <div class="panel-group" id="accordion" class="accordion">
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a data-toggle="collapse" data-parent=".accordion" href=".collapseOne">
          A 2
        </a>
      </h4>
    </div>
    <div id="collapseOne" class="panel-collapse collapse in collapseOne">
      <div class="panel-body">
     A 2
      </div>
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a data-toggle="collapse" data-parent=".accordion" href=".collapseTwo">
          B 2
        </a>
      </h4>
    </div>
    <div id="collapseTwo" class="panel-collapse collapse collapseTwo">
      <div class="panel-body">
        B 2
      </div>
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a data-toggle="collapse" data-parent=".accordion" href=".collapseThree">
          C 2
        </a>
      </h4>
    </div>
    <div id="collapseThree" class="panel-collapse collapse collapseThree">
      <div class="panel-body">
        C 2
      </div>
    </div>
  </div>
</div> 

  </div>
</div>