【发布时间】:2015-11-28 09:13:17
【问题描述】:
好的,我了解 JavaScript 并未应用于整个组,因为每个按钮都是不同组的一部分,但文档说这是使用 justified with button 标签的正确方法。这不是问题,除非我需要他们被证明是合理的。
所以我的问题是:我应该如何在所有三个按钮上整体使用 JavaScript?它应该作为一个简单的单选按钮组运行。
单击一个,其他的将被取消选中。任何建议都会很棒!
HTML:
<div class="btn-group btn-group-justified" role="group" aria-label="...">
<div class="btn-group">
<button type="button" class="btn btn-default">Low Cost/Effeciency</button>
</div>
<div class="btn-group">
<button type="button" class="btn btn-default active">Average</button>
</div>
<div class="btn-group">
<button type="button" class="btn btn-default">High Cost/Effeciency</button>
</div>
</div>
JavaScript:
$(function() {
$('body').on('click', '.btn-group button', function (e) {
$(this).addClass('active');
$(this).siblings().removeClass('active');
//other things I need to do
})
});
【问题讨论】:
标签: javascript jquery html twitter-bootstrap