Javascript 要求选中表格上的所有框

Javascript 要求选中表格上的所有框,javascript,html,forms,Javascript,Html,Forms,我试图得到一个表格,要求所有的复选框被选中,以表明该人已经阅读了所有章节,然后才允许提交。html就像 函数检查表() { 如果(!this.rsa.secOne.checked) { 警报(“必须选中所有框”); 返回false; } 否则如果(!this.rsa.secTwo.checked) { 警报(“必须选中所有框”); 返回false; } 否则如果(!this.rsa.secThree.checked) { 警报(“必须选中所有框”); 返回false; } 返回true; }

我试图得到一个表格,要求所有的复选框被选中,以表明该人已经阅读了所有章节,然后才允许提交。html就像

函数检查表()
{
如果(!this.rsa.secOne.checked)
{
警报(“必须选中所有框”);
返回false;
}
否则如果(!this.rsa.secTwo.checked)
{
警报(“必须选中所有框”);
返回false;
}
否则如果(!this.rsa.secThree.checked)
{
警报(“必须选中所有框”);
返回false;
}
返回true;
}

附件C

第一节
之所以出现错误,是因为在onSubmit回调函数上放置了大写为F的
checkForm()
,但创建函数时,它是
checkForm()


只需将
checkForm()
更改为
checkForm()

,您就得到了错误,因为您在onSubmit回调中使用了大写字母F的
checkForm()
,但创建函数时它是
checkForm()

只需使用
required
checkForm()
更改为
checkForm()

: 只需向每个输入元素添加一个
required
属性,如下所示:

<input type="checkbox" id="secOne" name="secOne" required>
<input type="checkbox" id="secTwo" name="secTwo" required>

提交
使用所需的
: 只需向每个输入元素添加一个
required
属性,如下所示:

<input type="checkbox" id="secOne" name="secOne" required>
<input type="checkbox" id="secTwo" name="secTwo" required>

提交
这将起作用:

function checkForm() {
  return [...document.querySelectorAll(".reqCheck")].every(el => el.checked)
}
为测试目的格式化:

函数检查表(){
const allChecked=[…document.queryselectoral(“.reqCheck”)].every(el=>el.checked)
console.log(全部选中)
返回全部已检查
}

第1节。
第2节。
第3节。
这将起作用:

function checkForm() {
  return [...document.querySelectorAll(".reqCheck")].every(el => el.checked)
}
为测试目的格式化:

函数检查表(){
const allChecked=[…document.queryselectoral(“.reqCheck”)].every(el=>el.checked)
console.log(全部选中)
返回全部已检查
}

第1节。
第2节。
第3节。