如何以编程方式检查Bootstrap按钮组(收音机)按钮

Csa*_*oth 10 javascript jquery buttongroup twitter-bootstrap

http://jsfiddle.net/rphpbqp9/

<div class="btn-group" data-toggle="buttons">
    <label class="btn btn-sm btn-primary success active">
        <input type="radio" name="options" id="optionFalse" checked />false
    </label>
    <label class="btn btn-sm btn-primary danger">
        <input type="radio" name="options" id="optionTrue" />true
    </label>
</div>

$('#optionTrue').button('toggle');
Run Code Online (Sandbox Code Playgroud)

我已经阅读了更多的问题答案,但没有一个有效.按钮切换不起作用,我试图添加/删除"活动"类,没有效果.我正在使用1.10 jQuery和3.1 Bootstrap.这应该是简单的,我把我的头发拉出来!

Ant*_*Chu 21

button()需要在类的元素上调用btn...

$('#optionTrue').closest('.btn').button('toggle');
Run Code Online (Sandbox Code Playgroud)

这将正确切换按钮并正确更新每个输入的已检查属性...

小提琴