使用javascript显示和隐藏可折叠

时间:2018-06-19 14:23:24

标签: javascript twitter-bootstrap-3 collapse

我无法显示和隐藏可折叠的引导程序。

由于引导程序由于加载了更多库而无法正常工作,因此如何使用JavaScript?

enter image description here

$('element').click(function() {
  if (open) {
    //close
  } else {
    //open
  }
});
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
  <div class="panel panel-default">
    <div class="panel-heading" role="tab" id="headingOne">
      <h4 class="panel-title">
        <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
          Collapsible Group Item #1
        </a>
      </h4>
    </div>
    <div id="collapseOne" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
      <div class="panel-body">
        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid
      </div>
    </div>
  </div>
  ...
</div>

1 个答案:

答案 0 :(得分:0)

您可以考虑使用jQuery的toggle,它将隐藏元素切换为可见元素,并将可见元素切换为隐藏元素。