Bootstrap开关按钮的渲染

1,375 阅读1分钟

{

field: 'visible',
title: '是否启用',
events: operateEvents,
formatter:function (value, row, index) {
    // 是否启用的按钮
    if(row.visible=='0'){
        return '<div class="switch LinkmanSwitch" id="mySwitch" data-on="primary" data-off="info">' +
            '<input type="checkbox" name="status" value="0" />' +
            '</div>'
    }else{
        return '<div class="switch LinkmanSwitch" id="mySwitch" data-on="primary" data-off="info">' +
            '<input type="checkbox" name="status" value="1" checked/>' +
            '</div>'
    }
}

},

 <!--开关插件-->
<script src="../../ajax/libs/bootstrap-switch/bootstrap-switch.min.js"></script>
<link rel="stylesheet" href="../../ajax/libs/bootstrap-switch/bootstrap-switch.css">

// 开关按钮的渲染

$('#mySwitch input').bootstrapSwitch({
onText: "NO",
offText: "OFF",
size: "small",
onSwitchChange: function (event, state) {
    if (state == true) {
        $(this).val("1");
    }else {
        $(this).val("0");
    }
    stats = $(this).val()
}

})