<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');
我已经阅读了更多问题的答案,但没有一个有效。 按钮切换不起作用,我尝试添加/删除“事件”类,但没有效果。我正在使用 1.10 jQuery 和 3.1 Bootstrap。这应该很简单,我正在拔头发!
最佳答案
button()
需要在类 btn
...
$('#optionTrue').closest('.btn').button('toggle');
这将正确切换按钮并正确更新每个输入的选中属性...
关于javascript - 如何以编程方式检查 Bootstrap 按钮组(单选)按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25589385/