twitter-bootstrap Bootstrap Switch - 单击按钮后更改状态
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31345638/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bootstrap Switch - Change state after clicking on button
提问by brunodd
I am using Bootstrap Switchplugin and Bootstrap Modal. Once the user clicks to change the Switch from onto offthe Modal box fades in asking for a confirmation.
我正在使用Bootstrap Switch插件和 Bootstrap Modal。一旦用户单击将 Switch 从on更改off为 Modal 框,就会出现要求确认的淡入淡出。
How do I change the Switch from onto offor from offto ononly after the user clicks on Confirm button? If the user clicks on Cancel then the Switch should go back to Offstatus.
如何在交换机从更改on到off或off到on只在确认用户点击按钮后?如果用户单击取消,则开关应返回Off状态。
$("#myswitch").bootstrapSwitch();
$('#myswitch').on('switchChange.bootstrapSwitch', function (e, data) {
$('#showModal').modal({
backdrop: 'static',
keyboard: false
});
});
回答by Maxime Peloquin
You can use the statemethod to prevent the switch from changing. Remember to use the third parameter to make sure the event is not executed again.
您可以使用该state方法来防止开关发生变化。请记住使用第三个参数来确保不会再次执行该事件。
$('#myswitch').bootstrapSwitch('state', !data, true);
Working example :
工作示例:
https://jsfiddle.net/hL0as0mv/169/
https://jsfiddle.net/hL0as0mv/169/
Full documentation : http://bootstrapswitch.site/methods.html

