3

我第一次使用 twitter boostrap 并且正在使用可折叠的手风琴。

当页面加载时,第一个项目默认打开,其余项目全部折叠。

我希望在页面加载时默认打开第二个项目和第一个项目和剩余项目。

有没有一种简单的方法可以实现这一目标?我试过玩这个data-toggle属性,但没有得到任何结果。

<div class="accordion" id="accordion2">
  <div class="accordion-group">
    <div class="accordion-heading">
      <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne">
        Name &amp; Location
      </a>
    </div>
    <div id="collapseOne" class="accordion-body collapse in">
      <div class="accordion-inner">
        <%= f.input :name %> <br/>

        <%= f.input :addr_1, label: 'Address' %> <br/>

        <%= f.input :addr_2, label: false %> <br/>

        <%= f.input :addr_3, label: false, placeholder: "County, State, Provence, Region etc" %> <br/>

        <%= f.input :country, label: false, :priority => [ "Ireland", "United Kingdom" ] %>  <br/>

        </div>
    </div>
  </div>

    <div class="accordion-group">
    <div class="accordion-heading">
      <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseTwo">
        Description
      </a>
    </div>
    <div id="collapseTwo" class="accordion-body collapse">
      <div class="accordion-inner">

        <%= f.input :description, :input_html => { :cols => 10, :rows => 3 } %> <br/>

        <%= f.input :looped, :as => :boolean %> 

        <%= f.input :duration_hours, :label => 'Duration',  :collection => 0..12, :include_blank => false, :hint => "hours" %>

        <%= f.input :duration_mins, collection: [ 0, 15, 30, 45 ], :include_blank => false, label: false, :hint => "mins" %>
      </div>
    </div>
  </div>


  <div class="accordion-group">
    <div class="accordion-heading">
      <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseThree">
        Images
      </a>
    </div>
    <div id="collapseThree" class="accordion-body collapse">
      <div class="accordion-inner">
        <%= f.simple_fields_for :photos do |builder| %>
          <%= render 'photo_fields', f: builder %>
        <% end %>
        <div style=clear:both;> </div>
        <%= link_to_add_fields "Add More", f, :photos %>
      </div>
    </div>
  </div>

  <div class="accordion-group">
    <div class="accordion-heading">
      <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseFour">
        Route
      </a>
    </div>
    <div id="collapseFour" class="accordion-body collapse">
      <div class="accordion-inner">
        <%= f.simple_fields_for :routes do |builder| %>
          <%= render 'route_fields', f: builder %>
        <% end %>
        <%= link_to_add_fields "Add Step", f, :routes %>
      </div>
    </div>
  </div>

  <div class="accordion-group">
    <div class="accordion-heading">
      <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseFive">
        Directions
      </a>
    </div>
    <div id="collapseFive" class="accordion-body collapse">
      <div class="accordion-inner">
        <%= f.simple_fields_for :directions do |builder| %>
          <%= render 'direction_fields', f: builder %>
        <% end %>
        <%= link_to_add_fields "Add More Directions", f, :directions %>
      </div>
    </div>
  </div>

</div>
4

1 回答 1

6

Bootstrap 使用in该类来确定默认打开哪些项目(不仅仅是在手风琴功能上),因此您可以将该类移动到#collapseTwodiv 并且它将默认打开。

于 2013-04-02T18:24:06.950 回答