按钮上的折叠面板单击 - 引导程序

时间:2016-07-19 20:24:52

标签: javascript html twitter-bootstrap angular

按正常引导按钮时如何使面板折叠?这是我的代码:

<div class="panel panel-primary" style="border-color: #464646;">
    <div class="panel-heading" style="border-color: #BBBBBB; height: 35px; padding-top: 3px;">
        <div style="float: left; margin-top: 5px;" data-toggle="collapse" href="#collapse1">Select Object</div>
    </div>
    <div id="collapse1" class="panel-collapse collapse">
        <div class="panel-body">
            <!--Object Buttons-->
            <button *ngFor="let object of objects" type="button" data-toggle="collapse" style="margin-right: 10px;" class="btn btn-primary" (click)="doThings();"</button>
        </div>
    </div>
</div>

单击panel-bodypanel-heading会崩溃,但我希望在单击其中一个'对象'按钮时让面板体折叠。

1 个答案:

答案 0 :(得分:4)

您可以将相同的data-target="#collapse1"应用于href所具有的按钮。

<强> HREF

<a data-toggle="collapse" href="#collapse1">Select Object</a>

按钮

<button class="btn btn-danger" type="button" data-toggle="collapse" data-target="#collapse1">

此外,您的按钮尚未关闭。缺少>来关闭它。

<button *ngFor="let object of objects" type="button" data-toggle="collapse" style="margin-right: 10px;" class="btn btn-primary" (click)="doThings();"

示例:

&#13;
&#13;
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="panel-group">
  <div class="panel panel-primary">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a data-toggle="collapse" href="#collapse1">Select Object</a>
      </h4>
    </div>
    <div id="collapse1" class="panel-collapse collapse">
      <div class="panel-body">
        <button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapse1">
          Button with the same data-target
        </button> Panel Body
      </div>
    </div>
  </div>
  <div class="panel panel-danger">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a data-toggle="collapse" href="#collapse2">Select Object</a>
      </h4>
    </div>
    <div id="collapse2" class="panel-collapse collapse">
      <div class="panel-body">
        <button class="btn btn-danger" type="button" data-toggle="collapse" data-target="#collapse2">
          Button with the same data-target
        </button> Panel Body
      </div>
    </div>
  </div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
&#13;
&#13;
&#13;