试试这个:
function changeSwitch(switch_id,active) {
var check = document.querySelector(switch_id);
if ( !check.checked && active ){
var c = $(check).next('span').attr("class").replace("switchery ","");
var l = {"switchery-large":"26px","switchery-small":"13px","switchery-default":"20px"};
$(check).prop("checked",true).next('span').attr("style","box-shadow: rgb(38, 185, 154) 0px 0px 0px 16px inset; border-color: rgb(38, 185, 154); background-color: rgb(38, 185, 154); transition: border 0.4s, box-shadow 0.4s, background-color 1.2s;").find('small').attr("style","left: "+l[c]+"; transition: background-color 0.4s, left 0.2s; background-color: rgb(255, 255, 255);");
}else if ( check.checked && !active ){
$(check).prop("checked",false).next('span').attr("style","box-shadow: rgb(223, 223, 223) 0px 0px 0px 0px inset; border-color: rgb(223, 223, 223); background-color: rgb(255, 255, 255); transition: border 0.4s, box-shadow 0.4s;").find('small').attr("style","left: 0px; transition: background-color 0.4s, left 0.2s;");
}
}
changeSwitch(".js-switch",true);
如果您想重置表单,请在使用之前执行以下操作:
changeSwitch(".js-switch",true);
$("#frm_id").trigger("reset");