hello!python!

bootstrapSwitch 使用

1、bootstrapSwitch 默认选项,加上checked表示true,不加表示false

<input type="checkbox" id="" name="status" checked data-size="small" value="1">

 


2、swich配置
$('[name="status"]').bootstrapSwitch({
    onText: "上架",
    offText: "下架",
    onColor: "danger",
    offColor: "info",
    size: "small",
    onSwitchChange: function (event, state) {
        if (state == true) {
            $(this).val("1");
        } else {
            $(this).val("2");
        }
    }
})

 


3、触发swich事件。
$('[name="status"]').on('switchChange.bootstrapSwitch', function (event, state) {
if (state == true) {
$.get("/gift/updatestatus", {
id: $(this).attr("id"),
status: '0'
}, function (data) {
console.log(data.result);
location.reload()

})
} else {
$.get("/gift/updatestatus", {
id: $(this).attr("id"),
status: '1'
}, function (data) {
console.log(data.result);
location.reload()

})

}
});

 

posted @ 2018-06-13 15:00  你坚持了吗  阅读(907)  评论(0编辑  收藏  举报
hello!python!