2014-12-05 69 views
0

這裏面之後是代碼:從一個手風琴改變到另一個點擊提交按鈕一個手風琴

<div class="panel-group" id="accordion"> 
    <div class="panel panel-default" id="panel1"> 
     <div class="panel-heading"> 
      <h4 class="panel-title"> 
       <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne"> 
        Collapsible Group Item #1 
       </a> 
      </h4> 
     </div> 
     <div id="collapseOne" class="panel-collapse collapse in"> 
      <div class="panel-body"> 
       Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS. 
      </div> 
     </div> 
    </div> 
    <div class="panel panel-default" id="panel2"> 
     <div class="panel-heading"> 
      <h4 class="panel-title"> 
       <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo"> 
        Collapsible Group Item #2 
       </a> 
      </h4> 
     </div> 
     <div id="collapseTwo" class="panel-collapse collapse"> 
      <div class="panel-body"> 
       Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS. 
      </div> 
     </div> 
    </div> 
    <div class="panel panel-default" id="panel3"> 
     <div class="panel-heading"> 
      <h4 class="panel-title"> 
       <a data-toggle="collapse" data-parent="#accordion" href="#collapseThree"> 
        Collapsible Group Item #3 
       </a> 
      </h4> 
     </div> 
     <div id="collapseThree" class="panel-collapse collapse"> 
      <div class="panel-body"> 
       Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS. 
      </div> 
     </div> 
    </div> 
</div> 




<!-- Post Info --> 
<div style='position: fixed; bottom: 0; left: 0; background: lightgray; width: 100%;'> 
    About this SO Question: <a href='http://stackoverflow.com/q/19936572/1366033'>Bootstrap3 Bind Collapse</a><br/> 
    Find documentation: <a href='http://getbootstrap.com/javascript/#collapse-usage'>Bootstrap Collapse Usage</a><br/> 
    Fork This Skeleton Here <a href='http://jsfiddle.net/KyleMit/kcpma/'>Bootrsap 3.0 Skeleton</a><br/> 
</div> 

的jsfiddle here。 我試圖通過添加和刪除in class來實現。它是第一次工作,當第二次嘗試時,它不是。

+0

我eddited你的問題。問題是我沒有在手風琴中看到任何提交按鈕,另一個問題是我沒有看到你試圖添加和刪除該類的位置。你能用完整的代碼更新你的jsfiddle嗎? – paulalexandru 2014-12-05 17:36:27

回答

1

面板內,您可以使用buttona元素使用data -attributes來打開其他面板如下:

<button class="btn btn-default" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">Open panel 2</button> 
<a class="btn btn-default" data-toggle="collapse" data-parent="#accordion" href="#collapseThree">Open panel 3</a>  

你問了提交,之後提交您的頁面重新加載(和重新加載之前的活動面板未知):

現在您可以將提交操作設置爲位置哈希:<form id="theform" action="#collapseThree">,請注意,這不會觸發重新加載。之後,你可以打開一個基於位置的哈希面板:

$(window).on('hashchange', function(e) { $(window.location.hash).collapse(); }); 

對於您設置表單動作爲基於位置的URL form id="theform" action="yourpage.html#collapseThree">可以打開面板時觸發頁面重載,例如情況哈希太:

if(window.location.hash) { 
$(window.location.hash).collapse(); 
} 

最後,您還可以防止表單形式重裝與e.preventDefault();提交後:

$('#theform').on('submit', function(e){ 
    e.preventDefault(); 
    $('#collapseThree').collapse(); 
}); 
相關問題