2012-11-18 267 views
0

如何在引導框架中更改按鈕的css顏色屬性? 例如,我的一個按鈕...更改按鈕的css顏色屬性

<button type="button" id="button1" class="btn btn-primary btn-large" onclick="checkAnswer(0)">Some text</button> 

一些jQuery的...

$(document).ready(function(){ 
    // Wrong answer! The selected button turns red. 
    $("#button1").click(function(){ 
     $("btn-primary").css("background-color", "red"); 
    }); 
}); 

感謝。

+0

請參閱本文以獲取完整說明。 http://stackoverflow.com/questions/13415030/twitter-bootstrap-2-custom-button-styling-not-working/13415671#13415671(有一些問題需要注意) – davidkonrad

回答

2

如果commment不放棄任何意義:),在這裏代碼

<button type="button" id="button1" class="btn btn-primary btn-large" onclick="checkAnswer(0)">Some text</button> 

<script type="text/javascript"> 
$("#button1").click(function() { 
    $(this).css('background-image','none') 
    .css('background-color','#FF0000') //red 
}); 
</script> 
+0

謝謝,對不起回覆評論。我必須在發佈後立即離開。這個例子很好用。 有趣的bg圖像需要重置。我會研究爲什麼如此。 – Leke

0

如果你不想改變樣式表,你可以通過改變類中使用不同的引導選項,紅色:

class="btn btn-danger btn-large" 

或藍色:

class="btn btn-primary btn-large" 

http://getbootstrap.com/css/#buttons-options