我正在为单选按钮使用bootstrap btn-group类。它们在实时服务器上不起作用。我的网站在example.com开发中,尽管它们在单独的html页面上工作。
<div class="row">
<section class="col-lg-2 col-xs-3">
<label>Gender:</label></section>
<section class="col-lg-4 col-xs-8">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary control-label input-group">
<input type="radio" name="gender" id="option2" autocomplete="off" value="male">Male
</label>
<label class="btn btn-primary ">
<input type="radio" name="gender" id="option3" autocomplete="off" value="female" checked> Female
</label>
</div>
</section>
</div>
最佳答案
$(document).ready(function(){
$('.gender').on('click', function() {
$('.checked').removeClass('checked');
$(this).addClass('checked');
});
});
@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
.checked {
background-color: #286090;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row">
<section class="col-lg-2 col-xs-3">
<label>Gender:</label>
</section>
<section class="col-lg-4 col-xs-8">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary control-label input-group gender">
<input type="radio" name="gender" id="option2" autocomplete="off" value="male">Male
</label>
<label class="btn btn-primary gender">
<input type="radio" name="gender" id="option3" autocomplete="off" value="female" checked> Female
</label>
</div>
</section>
</div>