有没有办法在循环中执行 !radios[0].checked && !radios[1].checked && !radios[2].checked 并有时保持 if 条件不变?我的代码是:
function afterLogin(event){
event.preventDefault();
if((!radios[0].checked && !radios[1].checked && !radios[2].checked) || userName.value === "" || numOfQuestions.value === ""){
skillMsg.innerHTML = "Please check one of the skills before login";
isTrue = false;
}else{
title[0].innerHTML = "Welcome " + userName.value;
loginForm.style.display = "none";
calForm.style.display = "block";
formsColor.style.backgroundColor = color.value;
startTheGame();
isTrue = true;
}
}
这就是我尝试做的:
function afterLogin(event){
event.preventDefault();
for(let i = 0; i < radios.length; i++){
if(!radios[i].checked || userName.value === "" || numOfQuestions.value === ""){
//change the plase here
skillMsg.innerHTML = "Please check one of the skills before login";
return false;
}else{
title[0].innerHTML = "Welcome " + userName.value;
loginForm.style.display = "none";
calForm.style.display = "block";
formsColor.style.backgroundColor = color.value;
//return true;
startTheGame();
//return true;
}
}
}
一只甜甜圈
DIEA
波斯汪
相关分类