Javascript 如何在没有数据标记的情况下为手风琴使用Bootstrap3折叠?

Javascript 如何在没有数据标记的情况下为手风琴使用Bootstrap3折叠?,javascript,jquery,twitter-bootstrap,twitter-bootstrap-3,Javascript,Jquery,Twitter Bootstrap,Twitter Bootstrap 3,我正在尝试为手风琴使用bootstrap collapse,而不使用所有数据-属性标记。我看到它在创建时切换,但我希望面板标题中的两个锚控制折叠。我知道如何使用jQuery手动执行此操作,但我认为只需调用.collapse(),就可以完成此操作 JS HTML 内容内容内容 内容内容内容 内容内容内容 您不能将数据-标记放在一边,因为折叠()函数用于初始化折叠组件,它不是事件触发器 如果不想手动设置每个数据切换属性,至少可以使用以下行: $('#accordion').find('.t-tit

我正在尝试为手风琴使用bootstrap collapse,而不使用所有
数据-
属性标记。我看到它在创建时切换,但我希望面板标题中的两个锚控制折叠。我知道如何使用jQuery手动执行此操作,但我认为只需调用
.collapse()
,就可以完成此操作

JS

HTML


内容

内容

内容

内容

内容

内容

内容

内容

内容


您不能将
数据-
标记放在一边,因为
折叠()
函数用于初始化折叠组件,它不是事件触发器

如果不想手动设置每个
数据切换
属性,至少可以使用以下行:

$('#accordion').find('.t-title, .t-toggle').attr('data-toggle', 'collapse');

如果将其放入JSFIDLE,您可能会得到一些帮助。
<!-- notices start -->
<div class="row spaced" id="notice">
  <div class="col">
    <div class="panel-group" id="accordion">
      <!-- start update -->
      <div class="panel panel-warning">
        <div class="panel-heading">
          <h4 class="panel-title">
            <a class="t-title" href="#notice-1">title</a>
            <a class="t-toggle" href="#notice-1">toggle</a>
          </h4>
        </div>
        <div id="notice-1" class="panel-collapse collapse in">
          <div class="panel-body"><p>content</p><p>content</p><p>content</p></div>
        </div>
      </div>
      <!-- / end update -->
      <!-- start update -->
      <div class="panel panel-success">
        <div class="panel-heading">
          <h4 class="panel-title">
            <a class="t-title" href="#notice-2">title</a>
            <a class="t-toggle" href="#notice-2">toggle</a>
          </h4>
        </div>
        <div id="notice-2" class="panel-collapse collapse">
          <div class="panel-body"><p>content</p><p>content</p><p>content</p></div>
        </div>
      </div>
      <!-- / end update -->
      <!-- start update -->
      <div class="panel panel-danger">
        <div class="panel-heading">
          <h4 class="panel-title">
            <a class="t-title" href="#notice-3">title</a>
            <a class="t-toggle" href="#notice-3">toggle</a>
          </h4>
        </div>
        <div id="notice-3" class="panel-collapse collapse">
          <div class="panel-body"><p>content</p><p>content</p><p>content</p></div>
        </div>
      </div>
      <!-- / end update -->
    </div>
  </div>
</div>
$('#accordion').find('.t-title, .t-toggle').attr('data-toggle', 'collapse');