document.querySelector('button[type="submit"]').addEventListener('click', () => {
const inputTags = Array.from(document.querySelectorAll('input'));
const textArea = document.querySelector('textarea');
inputTags.splice(inputTags.length, 0, textArea);
let output = "";
inputTags.forEach((input) => {
if(input.type == "checkbox" && input.checked == true ) {
output += input.nextElementSibling.textContent;
output += input.checked;
output += "n";
continue;
} else if(input.type == "radio" && input.checked == true) {
if(input.nextElementSibling.textContent == "I have money and can pay for this") {
output += input.nextElementSibling.textContent.toLowerCase();
output += "n";
}
} else {
output += input.nextElementSibling.textContent;
output += input.value;
}
})
alert(output);
})
您正试图在循环之外使用continue
。forEach
调用不算作在循环中。相反,只需返回或确保在函数完成之前没有发生任何其他事情。
看起来你可以去掉continue
,一切都会好起来的。
您不是在循环中,而是在函数(forEach(中,因此使用return而不是continue