
實(shí)現(xiàn)效果
實(shí)現(xiàn)方式:
- 創(chuàng)建checkbox元素:
<input type="checkbox" checked="" />
- 將checkbox樣式改為switch開(kāi)關(guān)樣式,并加上綁定代碼:
<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')); //打印當(dāng)前switch狀態(tài)
});
});
});
</script>