[英]Bootstrap uncheck checkbox and style
我有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 ?
});
为此,您应该真正使用单选按钮,而不是复选框,并设置它们的样式为复选框(如果您更喜欢这种外观)。 所以代替
<input type="checkbox" autocomplete="off">
只需使用
<input type="radio" autocomplete="off" name="X">
并确保所有无线电具有相同的名称属性。
/* 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; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> <link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"> <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 id="checkboxPencil" type="radio" autocomplete="off" name="menu"> </label> <label class="btn btn-default btn-lg no-border"> <span id="btnSquare" class="glyphicon glyphicon-th-large" aria-hidden="true"></span> <input id="checkboxSquare" type="radio" autocomplete="off" name="menu"> </label> <label class="btn btn-default btn-lg no-border"> <span id="btnSquare" class="glyphicon glyphicon-th-large" aria-hidden="true"></span> <input id="checkboxSquare2" type="radio" autocomplete="off" name="menu"> </label> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.