我使用了以下按钮组,当在组中单击这些按钮或按钮时,所点击的按钮的颜色必须高亮。如何使用切换类实现此目的,或者如果不是toggleclass,请与任何其他方法分享。
<div class="btn-group" data-toggle="buttons-checkbox">
<div class='input-group input-group-sm'>
<span class="input-group-addon">Week</span></div>
<button class="btn" name="WeekButtonGroup" id="week1_sat">
S</button>
<button class="btn" name="WeekButtonGroup" id="week1_sun">
S</button>
<button class="btn" name="WeekButtonGroup" id="week1_mon">
M</button>
<button class="btn" name="WeekButtonGroup" id="week1_tue">
T</button>
<button class="btn" name="WeekButtonGroup" id="week1_wen">
W</button>
<button class="btn" name="WeekButtonGroup" id="week1_thu">
T</button>
<button class="btn" name="WeekButtonGroup" id="week1_fri">
F</button>
</div>
</div>
function highlightwhenclicked() {
$('[name="WeekButtonGroup"]').each(function (index, element) {
$(this).click(function () {
$(this).removeClass('active');
}
})
}
我知道$(this).toggleClass可以做到这一点但是怎么做?我不介意什么颜色,但点击时按钮必须高亮。提前谢谢。
答案 0 :(得分:0)
这样的事情怎么样?
$('.btn').click(function() {
$(this).toggleClass('clicked');
});