![实现效果](https://github.com/jxsr3623/resource/blob/master/images/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7-2016-08-04-%E4%B8%8B%E5%8D%881.37.21.png?raw=true)
实现方式:
- 创建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>
网友评论