帮我解决Bootstrap switch Toggle - One打开,另一个打开使用checkbox和jQuery。
<input type="checkbox" data-toggle="toggle" data-style="ios" data-size="normal" data-on="​" data-off="​" onclick="change_ins(1)" class="switch switch-on toggle" checked value="true" id="toggle1">
<input type="checkbox" data-toggle="toggle" data-style="ios" data-size="normal" data-on="​" data-off="​" onclick="change_ins(2)" class="switch switch-off toggle" id="toggle2">
<input type="checkbox" data-toggle="toggle" data-style="ios" data-size="normal" data-on="​" data-off="​" onclick="change_ins(3)" class="switch switch-off toggle" id="toggle3">
<input type="checkbox" data-toggle="toggle" data-style="ios" data-size="normal" data-on="​" data-off="​" onclick="change_ins(4)" class="switch switch-off toggle" id="toggle4">
<input type="checkbox" data-toggle="toggle" data-style="ios" data-size="normal" data-on="​" data-off="​" onclick="change_ins(5)" class="switch switch-off toggle" id="toggle5">
答案 0 :(得分:1)
$(".toggle123").change(function() {
var tid= this.id;
if ($(this).is(":checked")) {
$('.toggle123').each(function() {
if(this.id != tid){ $("#"+this.id).bootstrapToggle('off'); }
});
/* $(".toggle").bootstrapToggle('off');
*/
}
});
&#13;
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet"/>
<input type="checkbox" data-toggle="toggle" data-style="ios" data-size="normal" data-on="​" data-off="​" class="switch switch-on toggle toggle123" id="toggle1">
<input type="checkbox" data-toggle="toggle" data-style="ios" data-size="normal" data-on="​" data-off="​" class="switch switch-off toggle toggle123" id="toggle2">
<input type="checkbox" data-toggle="toggle" data-style="ios" data-size="normal" data-on="​" data-off="​" class="switch switch-off toggle toggle123" id="toggle3">
<input type="checkbox" data-toggle="toggle" data-style="ios" data-size="normal" data-on="​" data-off="​" class="switch switch-off toggle toggle123" id="toggle4">
<input type="checkbox" data-toggle="toggle" data-style="ios" data-size="normal" data-on="​" data-off="​" class="switch switch-off toggle toggle123" id="toggle5">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>
&#13;