【发布时间】:2017-04-06 18:19:57
【问题描述】:
我有 3 个按钮/复选框,如果我点击任何一个它会被选中,如果我点击当前一个,我如何让所有其他按钮取消选中。
https://jsfiddle.net/DTcHh/31573/
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default btn-lg no-border">
<span id="btnPencil" class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
<input type="checkbox" autocomplete="off">
</label>
<label class="btn btn-default btn-lg no-border">
<span class="glyphicon glyphicon-th-large" aria-hidden="true"></span>
<input type="checkbox" autocomplete="off">
</label>
<label class="btn btn-default btn-lg no-border">
<span class="glyphicon glyphicon-th-large" aria-hidden="true"></span>
<input type="checkbox" autocomplete="off">
</label>
</div>
btnp = document.getElementById(btnPencil)
btnp.addEventListener('change', function() {
// 1. check current button / checkbox
// 2. uncheck other buttons / checkbox
// bootstrap uncheck / check style ?
});
【问题讨论】:
-
为什么不改用
radio buttons?
标签: javascript html twitter-bootstrap checkbox