twitter bootstrap崩溃第一项&在加载时打开第二个项目

时间:2013-04-02 18:12:23

标签: javascript twitter-bootstrap

我第一次使用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>

1 个答案:

答案 0 :(得分:6)

Bootstrap使用in类来确定默认打开哪些项目(而不仅仅是在手风琴功能上),这样您就可以将该类移动到#collapseTwo div,默认情况下它会打开。