我正在尝试使用 JavaScript/Html 创建一个“测验”。在我开始之前,我只想说,我是在 4 小时前被介绍到这种语言的,所以请耐心等待我。这是我到目前为止所写的:
<!DOCTYPE html>
<html>
<body>
<form name="input" action="html_form_action.asp" method="get">
<input type="radio" name="Q1" value="A1">A1<br>
<input type="radio" name="Q1" value="A2">A2<br>
<input type="radio" name="Q1" value="A3">A3<br>
<input type="radio" name="Q1" value="A4">A4<br><br>
<input type="radio" name="Q2" value="A1">A1<br>
<input type="radio" name="Q2" value="A2">A2<br>
<input type="radio" name="Q2" value="A3">A3<br>
<input type="radio" name="Q2" value="A4">A4<br><br>
<input type="radio" name="Q3" value="A1">A1<br>
<input type="radio" name="Q3" value="A2">A2<br>
<input type="radio" name="Q3" value="A3">A3<br>
<input type="radio" name="Q3" value="A4">A4<br><br>
<input type="radio" name="Q4" value="A1">A1<br>
<input type="radio" name="Q4" value="A2">A2<br>
<input type="radio" name="Q4" value="A3">A3<br>
<input type="radio" name="Q4" value="A4">A4<br><br>
<input type="radio" name="Q5" value="A1">A1<br>
<input type="radio" name="Q5" value="A2">A2<br>
<input type="radio" name="Q5" value="A3">A3<br>
<input type="radio" name="Q5" value="A4">A4<br><br>
<input type="radio" name="Q6" value="A1">A1<br>
<input type="radio" name="Q6" value="A2">A2<br>
<input type="radio" name="Q6" value="A3">A3<br>
<input type="radio" name="Q6" value="A4">A4<br><br>
<input type="radio" name="Q7" value="A1">A1<br>
<input type="radio" name="Q7" value="A2">A2<br>
<input type="radio" name="Q7" value="A3">A3<br>
<input type="radio" name="Q7" value="A4">A4<br><br>
<input type="radio" name="Q8" value="A1">A1<br>
<input type="radio" name="Q8" value="A2">A2<br>
<input type="radio" name="Q8" value="A3">A3<br>
<input type="radio" name="Q8" value="A4">A4<br><br>
<input type="radio" name="Q9" value="A1">A1<br>
<input type="radio" name="Q9" value="A2">A2<br>
<input type="radio" name="Q9" value="A3">A3<br>
<input type="radio" name="Q9" value="A4">A4<br><br>
<input type="radio" name="Q10" value="A1">A1<br>
<input type="radio" name="Q10" value="A2">A2<br>
<input type="radio" name="Q10" value="A3">A3<br>
<input type="radio" name="Q10" value="A4">A4<br><br>
<script>
function checkTest()
{
var count = 0;
if ($('input:radio[name=Q1]:checked').val() == A1);
{
count = count + 1;
}
if ($('input:radio[name=Q2]:checked').val() == A1);
{
count = count + 1;
}
if ($('input:radio[name=Q3]:checked').val() == A1);
{
count = count + 1;
}
if ($('input:radio[name=Q4]:checked').val() == A1);
{
count = count + 1;
}
if ($('input:radio[name=Q5]:checked').val() == A1);
{
count = count + 1;
}
if ($('input:radio[name=Q6]:checked').val() == A1);
{
count = count + 1;
}
if ($('input:radio[name=Q7]:checked').val() == A1);
{
count = count + 1;
}
if ($('input:radio[name=Q8]:checked').val() == A1);
{
count = count + 1;
}
if ($('input:radio[name=Q9]:checked').val() == A1);
{
count = count + 1;
}
if ($('input:radio[name=Q10]:checked').val() == A1);
{
count = count + 1;
}
if (count > 6)
{
alert("Congratulations! You Passed!");
}
else
{
alert("You answered too many questions incorrectly. Try again.");
}
}
</script>
<button type="button" onclick="checkTest()">Submit Test!</button>
</form>
我认为,如果我只为所有答案选择“A1”,我会收到祝贺警报,但我什么也得不到。我拿到
($('input:radio[name=Q10]:checked').val()
直接来自该网站上的不同帖子,所以我认为这不是问题。请帮忙!!
编辑:我知道 Javascript 是一种不好的方法,但我真的只是想降低语言,此外,这只会在极小的范围内使用。