js修改Switchery复选框的状态

声明一个switchery插件,绑定到一个input上

js代码

var mySwitch = new Switchery($('#blacklist')[0], {
            size:"small",
            color: '#0D74E9'
});
调用
//Checks the switch
setSwitchery(mySwitch, true);
//Unchecks the switch
setSwitchery(mySwitch, false);
/**
 * 切换Switchery开关函数  switchElement Switchery对象,checkedBool 选中的状态
 */
function setSwitchery(switchElement, checkedBool) {
    if((checkedBool && !switchElement.isChecked()) || (!checkedBool && switchElement.isChecked())) {
        switchElement.setPosition(true);
        switchElement.handleOnchange(true);
    }
}
<input type="checkbox" id="blacklist" name="blacklist"/>

 

posted on 2019-06-12 09:31  静以修身俭以养德  阅读(896)  评论(0编辑  收藏  举报

导航