jquery修改Switchery复选框的状态

script

//选择框
var mySwitch;
/*
 * 初始化Switchery
 * * classNmae class名
 */
function initSwitchery(className) {
    mySwitch = new Switchery($(className)[0], {
        color: "#1AB394"
    });
}
/*
 * 切换Switchery开关函数
 * * switchElement Switchery对象
 * * checkedBool 选中的状态
 */
function setSwitchery(switchElement, checkedBool) {
    if ((checkedBool && !switchElement.isChecked()) || (!checkedBool && switchElement.isChecked())) {
        switchElement.setPosition(true);
        switchElement.handleOnchange(true);
    }
}

使用方法

//Checks the switch
setSwitchery(mySwitch, true);
//Unchecks the switch
setSwitchery(mySwitch, false);
原文地址:https://www.cnblogs.com/feigao/p/6185384.html