21

我正在使用 bootstrap 提供的折叠插件,这是一个 jquery 简单插件

但是它默认折叠,如何修改使折叠项默认隐藏,只有当我按下标题时,项目才会折叠并显示?谢谢

插件文档,几行,一分钟

$(document).ready( function () {
$(".collapse").collapse()({
  toggle: false,
  show: false
  });
} );

这是html:

<div class="accordion-group">
            <div class="alert alert-info" data-toggle="collapse" href="#collapse1" style="margin-bottom:0px;">                     
              Collapsible #1
                  </div>   
          <div id="collapse1" class="accordion-body collapse" style="background-color:#ffffff;">
               content1
           </div>
                           <div class="alert alert-info" data-toggle="collapse" href="#collapse2" style="margin-bottom:0px;">                     
              Collapsible #2
                  </div>   
          <div id="collapse2" class="accordion-body collapse" style="background-color:#ffffff;">
               content2
           </div>

4

2 回答 2

59

对于 Bootstrap 3,有些事情发生了变化。以下代码在 Bootstrap 3 中完成了您想要的功能

如果您希望面板主体默认显示:

<div id="collapseOne" class="panel-collapse collapse in">

如果您希望面板主体默认隐藏:

<div id="collapseOne" class="panel-collapse collapse">

这是一个例子:

<div class="bs-example">
    <div class="panel-group" id="accordion">

          <!- Repeat For Next Panel------->
        <div class="panel panel-default">
            <div class="panel-heading">
                <h4 class="panel-title">
                    <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
                       xxxxxxxxxxxHERE IS THE HEADER CONTENTSxxxxxxxxxxxx
                    </a>
                </h4>
           </div>
               <div id="collapseOne" class="panel-collapse collapse in">
                   <div class="panel-body">
                       xxxxxxxxxxxHERE IS THE BODY CONTENTSxxxxxxxxxxxx
                   </div>
               </div> 
         </div>
            <!- Repeat For Next Panel---(but change <div id="collapseTwo")--->

     </div>
 </div>
于 2013-10-08T18:38:04.730 回答
1
<div class="accordion-group collapse">
   <div class="alert alert-info" data-toggle="collapse" href="#collapse1" style="margin-bottom:0px;">                     
          Collapsible #1
   </div>   
   <div id="collapse1" class="accordion-body collapse" style="background-color:#ffffff;">
           content1
   </div>
   <div class="alert alert-info" data-toggle="collapse" href="#collapse2" style="margin-bottom:0px;">                     
          Collapsible #2
    </div>   
    <div id="collapse2" class="accordion-body collapse" style="background-color:#ffffff;">
          content2
    </div>
</div>
于 2017-01-23T09:42:30.720 回答