根据检查哪个收音机,我想切换两个类“leftChoice”和“rightChoice”不幸的是代码不起作用。我试图在没有 jQuery 的情况下使用纯 JS。也许有更简单的方法来获得结果。
var wrapper = document.getElementById('wrapper');
var choices = document.getElementsByName("choices");
var checkedChoice = "";
wrapper.classList.remove("rightChoice");
wrapper.classList.add("leftChoice");
choices.onchange(function() {
for (var i = 0, length = choices.length; i < length; i++) {
if (choices[i].checked) {
checkedChoice = choices[i].value;
break;
}
}
if(checkedChoice == "one"){
wrapper.classList.remove("rightChoice");
wrapper.classList.add("leftChoice");
}
else if(checkedChoice == "two"){
wrapper.classList.remove("leftChoice");
wrapper.classList.add("rightChoice");
}
});
https://jsfiddle.net/Lo6pzn1a/
素胚勾勒不出你
相关分类