实现方式:
- 创建checkbox元素:
<input type="checkbox" checked="" />
- 将checkbox样式改为switch开关样式,并加上绑定代码:
<script type="text/javascript">
require(['bootstrap.switch','util'], function($,util){
$(function(){
$(':checkbox').bootstrapSwitch();
$(':checkbox').on('switchChange.bootstrapSwitch', function(e, state){
console.log($(this).bootstrapSwitch('state')); //打印当前switch状态
});
});
});
</script>