很明显,我需要学习 javascript。我正在尝试编写一个可以脱机工作的测试,所以我不能使用 PHP,而是使用 javascript。现在我有一个测试,它会给我正确答案数量的分数。我这样做的方法是将正确为 1 和不正确为 0 的值相加。所以,我可以得到正确答案的数量。但是,我真正想要的是计算 Kappa 分数。为此,我需要知道此表中每个组的计数:
True
Y N
Tester Y 11 01
N 10 00
这是我的测验:测试
<script type="text/javascript">
function getRBValue(group) {
//loop
for ( var b = 0; b < group.length; ++b ) {
if ( group[b].checked )
return Number(group[b].value);
}
return 0; }
function Score(form) {
var total = 0;
for ( var q = 1; q <= 10; ++q ) {
total += getRBValue( form["q"+q] );
}
form.score.value = total;
alert("You got " + total + " questions right!");
}
</script>
</head>
<body>
<h1>test</h1>
<p>The following exam will allow you to evaluate your ability to grade Trachoma.</p>
</body>
<form name="prequiz" onsubmit="Score(this); return false;">
<table cellpadding=15px border="0" width="65%" summary= "Questions and options are organized in a table.">
<tbody>
<tr> <td>
<b><img src="pics/1.jpeg"</b><br/>
<br/><input type="radio" name="q1" value="0" > Present<br/>
<br/><input type="radio" name="q1" value="1" > Absent<br/>
</td> </tr>
<tr>
<td>
<b><img src="pics/2.jpeg"</b><br/>
<br/> <input type="radio" name="q2" value="0" > Present<br/>
<br/> <input type="radio" name="q2" value="1" > Absent<br/>
</td> </tr>
<tr>
<td>
<b><img src="pics/3.jpeg"</b><br/>
<br/> <input type="radio" name="q3" value="1" > Present<br/>
<br/> <input type="radio" name="q3" value="0" > Absent<br/>
</td> </tr>
<tr>
<td>
<b><img src="pics/4.jpeg"</b><br/>
<br/> <input type="radio" name="q4" value="0" > Present<br/>
<br/> <input type="radio" name="q4" value="1" > Absent<br/>
</td> </tr>
<tr>
<td>
<b><img src="pics/5.jpeg"</b><br/>
<br/> <input type="radio" name="q5" value="0" > Present<br/>
<br/> <input type="radio" name="q5" value="1" > Absent<br/>
</td> </tr>
<tr>
<td>
<b><img src="pics/6.jpeg"</b><br/>
<br/> <input type="radio" name="q6" value="0" > Present<br/>
<br/> <input type="radio" name="q6" value="1" > Absent<br/>
</td> </tr>
<tr>
<td>
<b><img src="pics/7.jpeg"</b><br/>
<br/> <input type="radio" name="q7" value="0" > Present<br/>
<br/> <input type="radio" name="q7" value="1" > Absent<br/>
</td> </tr>
<tr>
<td>
<b><img src="pics/8.jpeg"</b><br/>
<br/> <input type="radio" name="q8" value="1" > Present<br/>
<br/> <input type="radio" name="q8" value="0" > Absent<br/>
</td> </tr>
<tr>
<td>
<b><img src="pics/9.jpeg"</b><br/>
<br/> <input type="radio" name="q9" value="1" > Present<br/>
<br/> <input type="radio" name="q9" value="0" > Absent<br/>
</td> </tr>
<tr>
<td>
<b><img src="pics/10.jpeg"</b><br/>
<br/> <input type="radio" name="q10" value="0" > Present<br/>
<br/> <input type="radio" name="q10" value="1" > Absent<br/>
</td> </tr>
</tbody> </table> </center>
<br><br>
<input type="submit" name="submit" value="Score exam now">
<br/><br/>
<b>Your score:</b><input type="text" name="score" readonly="readonly" />
<br/>
</form> </html>