首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何对没有数据标记的手风琴使用引导3折叠?

如何对没有数据标记的手风琴使用引导3折叠?
EN

Stack Overflow用户
提问于 2013-11-21 13:13:30
回答 1查看 5.5K关注 0票数 2

我试图在没有所有data-属性标记的情况下对手风琴使用引导折叠。我看到它在创建上切换,但我希望面板标题中的两个锚控制崩溃。我知道如何用jQuery手动完成这个任务,但是我认为我应该能够通过对.collapse()的一个调用来完成这个任务。

JS

代码语言:javascript
复制
$('.collapse').collapse();
//$('.t-title,.t-toggle').collapse(); // also tried this with no luck

HTML

代码语言:javascript
复制
<!-- 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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-04 20:52:16

您不能把data-标记放在一边,因为collapse()函数是用来初始化折叠组件的,它不是事件触发器。

如果不想手动设置每个data-toggle属性,至少可以使用以下行:

代码语言:javascript
复制
$('#accordion').find('.t-title, .t-toggle').attr('data-toggle', 'collapse');

引线

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20121982

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档