我尝试使用以下代码单击以前选择的按钮,使Bootstrap btn-group无法选择:
$(document).ready(function() {
$('label.btn').click(function(e) {
if ($(this).hasClass('active')) {
$(this).removeClass('active');
}
});
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div id="note_reactivity" class="btn-group notes" data-toggle="buttons">
<label id="1" class="btn btn-primary">
<input type="radio">1
</label>
<label id="2" class="btn btn-primary">
<input type="radio">2
</label>
<label id="3" class="btn btn-primary">
<input type="radio">3
</label>
<label id="4" class="btn btn-primary">
<input type="radio">4
</label>
</div>Run Code Online (Sandbox Code Playgroud)
似乎我的代码在click事件中删除了"active"类,但它刚刚重新出现.你知道怎么做吗 ?