Bootstrap取消选中复选框和样式

时间:2017-04-06 10:09:18

标签: javascript html twitter-bootstrap checkbox

我有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 ?
});

2 个答案:

答案 0 :(得分:0)

你应该真的使用单选按钮,而不是复选框,并将它们设置为看起来像复选框(如果你喜欢这样的样子)。而不是

<input type="checkbox" autocomplete="off">

只需使用

<input type="radio" autocomplete="off" name="X">

确保所有无线电都具有相同的名称属性。

答案 1 :(得分:0)

[('b', 4), ('b', 5), ('b', 6), ('a', 1), ('a', 2)]
/* Latest compiled and minified JavaScript included as External Resource */
/* Latest compiled and minified CSS included as External Resource*/

/* Optional theme */
@import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');

body {
    margin: 10px;
}