Jquery手风琴默认不会崩溃

时间:2012-04-13 16:58:19

标签: javascript jquery jquery-ui twitter-bootstrap accordion

我正在使用bootstrap提供的崩溃插件 这是一个jquery简单插件

然而它默认崩溃,如何修改以便崩溃项目默认隐藏,只有当我按下标题,然后项目崩溃并显示?谢谢

The document of the plugin, just few line so it only takes one minute

$(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>

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分: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>