我正在使用Bootstrap 2.3.2
,我似乎無法使radio buttons
正常工作。我正在使用Bootstrap網站的代碼:如何使用Bootstrap單選按鈕?
<div class="btn-group" data-toggle="buttons-radio">
<button type="button" class="btn btn-primary">Left</button>
<button type="button" class="btn btn-primary">Middle</button>
<button type="button" class="btn btn-primary">Right</button>
</div>
我需要從這裏做什麼?有了這個,我得到3個按鈕,但點擊它們並不會將它們更改爲活動狀態,並且看起來並不像它們已被點擊。
編輯:
如果我初始化按鈕JS像這樣:
$('.btn-group').button();
爲組時,生成此標記:
<div class="btn-group ui-button ui-widget ui-state-default ui-corner-all
ui-button-text-only" data-toggle="buttons-checkbox"
role="button" aria-disabled="false">
<span class="ui-button-text">
<button type="button" class="btn btn-primary">Left</button>
<button type="button" class="btn btn-primary">Middle</button>
<button type="button" class="btn btn-primary">Right</button>
</span>
</div>
與此相比在自舉網址:
<div class="btn-group" data-toggle="buttons-radio">
<button type="button" class="btn btn-primary">Left</button>
<button type="button" class="btn btn-primary">Middle</button>
<button type="button" class="btn btn-primary active">Right</button>
</div>
不知道爲什麼它在這裏工作不同。
您是否包含了所需的JavaScript文件以支持該功能? –
@StevenV是的,我包括boostrap.js,它看起來具有所有組件的所有JS。我需要在JS中初始化它們嗎?因爲現在我所擁有的就是上面的內容。 – sbonkosky
是的。你需要使用'$('。btn-group')。button()'來啓動這個功能。 –