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事件
    "switchChange": function () {
        $('[name="switch"]').on('switchChange.bootstrapSwitch', function (event, state) {
            console.log(event);
            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()
                    })
            }
        });
    },

表格的話,需要在加載回調內執行swich配置

            onLoadSuccess: function () {
                list.initSwitch();
            }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM