2016-03-10 107 views
0

我使用與引導Glyphicon組件按鈕,並有大量的按鈕中的一個頁面上,它是利用塌陷顯示隱藏section.Here是例子的代碼我有更改圖標按鈕打開引導

<button type="button" class="btn btn-primary" data-toggle="collapse" data-target="#sixts-section-collapse">Prijava <span class="glyphicon glyphicon-menu-down"></span></button> 

<button type="button" class="btn btn-primary" data-toggle="collapse" data-target="#sixts-section-collapse">Prijava <span class="glyphicon glyphicon-menu-down"></span></button> 

<button type="button" class="btn btn-primary" data-toggle="collapse" data-target="#sixts-section-collapse">Prijava <span class="glyphicon glyphicon-menu-down"></span></button> 

什麼我需要的是,當用戶點擊該按鈕,並顯示崩潰只是將該圖標從下降上漲,我知道我可以使全球所有,但我只需要檢查該按鈕和該按鈕顯示另一個圖標。這意味着,當是關閉的圖標下來,打開時圖標了

回答

3
$(document).ready(function(){ 
    $("button[data-toggle=collapse]").click(function(){ 
     $(this).find('span:first').toggleClass('glyphicon-chevron-down glyphicon-chevron-up') 
    }); 
}); 

工作演示

$(".collapse").collapse() 
 
$("button[data-toggle=collapse]").click(function(){ 
 
     $(this).find('span:first').toggleClass('glyphicon-chevron-down glyphicon-chevron-up') 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/> 
 
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> 
 
<div class="container"> 
 
    <div class="panel-group" id="accordion"> 
 
     <div class="panel panel-default"> 
 
     <div class="panel-heading"> 
 
      <h4 class="panel-title"> 
 
      <button type="button" class="btn btn-primary" data-toggle="collapse" data-target="#demo"> 
 
       <span class="glyphicon glyphicon-chevron-down"></span> Open 
 
      </button> 
 
      </h4> 
 
     </div> 
 
     <div id="demo" class="panel-collapse collapse in"> 
 
      <div class="panel-body"> 
 
      Contents:Thank you to help me solve the problem, you're a great guy! 
 
      </div> 
 
     </div> 
 
     </div> 
 
    </div> 
 
</div>

+0

我猜OP是尋找撥動... – Rayon

+0

問題是它改變了圖標,但是當我關閉它時我想回到原來的 –

+1

May b e ['toggleClass(「AB」);'](http://stackoverflow.com/questions/7002039/easiest-way-to-toggle-2-classes-in-jquery)=>這將刪除類A並添加B類 – Rayon

1
$(document).on('click', '[data-toggle="collapse"]', function() {  
    $(this).toggleClass('glyphicon-menu-down glyphicon-menu-up'); 
}); 
+0

也行不通:( –

+0

修改了一下。 – no81no