0
我正在使用this library来实现切换按钮。我有两个切换按钮。我的目的是在打开其中一个时,另一个应该关掉。引导切换 - 一个打开,另一个打开
由于库指示,我创建两个input
元素:
<input type="checkbox" data-toggle="toggle" data-style="ios" data-size="normal" data-on="​" data-off="​" class="switch switch-on" checked value="true">
<input type="checkbox" data-toggle="toggle" data-style="ios" data-size="normal" data-on="​" data-off="​" class="switch switch-off">
而我的jQuery代码来处理它们:
$('.switch-on').change(function(){
$(this).removeClass('switch-on');
$(this).addClass('switch-off');
$(this).bootstrapToggle();
});
$('.switch-off').click(function(){
$(this).removeClass('switch-off');
$(this).bootstrapToggle();
$('.switch-on').click();
$(this).addClass('switch-on');
});
我已经尝试了很多方法,包括更改类名,触发事件,但完全徒劳。当我检查元素时,类名甚至没有改变。为什么它不工作?
一次检查此[链接](https://jsfiddle.net/knvnx2ks/1/) – rahulsm