嗨,我在检查是否检查了任何单选按钮时遇到了一些问题,我得到了这个结果: Uncaught TypeError: Cannot read property 'checked' of null when I run it 与此相关的代码是:
function validateForm() {
var msg="";
var LoE="";
...some code
for (var i=0; i<3; i++) {
if ((document.getElementById('"LoE" + i').checked)){
LoE="";
break;
}
Else
{
result = false;
msg+="You need to chose your level of entry";
}
}
...some more code
}
和正在检查的单选按钮。它们在一个名为 ExamEntry 的表格中
<tr>
<td><input type = "radio" name = "LevelOfEntry" id = "LoE0" value = "GCSE">GCSE</td>
</tr>
<tr>
<td><input type = "radio" name = "LevelOfEntry" id = "LoE1" value = "AS">AS</td>
</tr>
<tr>
<td><input type = "radio" name = "LevelOfEntry" id = "LoE2" value = "A2">A2</td>
</tr>
谢谢您的帮助。
编辑删除了评论中建议的单引号并替换为:
if ((document.getElementById("LoE" + i).checked)){
现在只得到在这部分代码中未指定的错误:
Else
{
result = false;
msg+="You need to chose your level of entry";
}
}
编辑:解决。非常感谢大家