首先需要引用
<script src="~/Content/AdminLTE-3.0.1/plugins/bootstrap-switch/js/bootstrap-switch.js"></script>
前端代码
<input type="checkbox" name="state" id="cbSwitch" checked data-bootstrap-switch data-off-color="danger" data-on-color="success" >
$(function () {
//初始化,不然显示不出来
$("input[data-bootstrap-switch]").each(function () {
$(this).bootstrapSwitch('state', false);
//$(this).bootstrapSwitch('state', $(this).prop('unchecked'));
//console.log('bootstrap')
});
//事件
$("#cbSwitch").on('switchChange.bootstrapSwitch', function (e, state) {
//console.log('bootstrap1')
});
});