我尝试进行测验/考试申请。创建单选题我没有问题(我的参考来自http://www.javascriptkit.com/script/cut180.shtml),但我仍然对如何制作单选题感到困惑。对于单选,我可以简单地使用单选按钮:
<form method="POST" name="myquiz">
<div class="qheader">
9) What's the world's most widely spoken language?</div>
<div class="qselections">
<input type="radio" value="a" name="question9">a) English<br>
<input type="radio" value="b" name="question9">b) Spanish<br>
<input type="radio" value="c" name="question9">c) Mandarin<br>
<input type="radio" value="d" name="question9">d) French<br>
</div>
</form>
对于评分,他们使用 javascript:
//Enter total number of questions:
var totalquestions=10
//Enter the solutions corresponding to each question:
var correctchoices=new Array()
correctchoices[1]='a' //question 1 solution
correctchoices[2]='a' //question 2 solution, and so on.
correctchoices[3]='c'
correctchoices[4]='c'
correctchoices[5]='c'
correctchoices[6]='c'
correctchoices[7]='b'
correctchoices[8]='b'
correctchoices[9]='c'
correctchoices[10]='b'
/////Don't edit beyond here//////////////////////////
function gradeit(){
var incorrect=null
for (q=1;q<=totalquestions;q++){
var thequestion=eval("document.myquiz.question"+q)
for (c=0;c<thequestion.length;c++){
if (thequestion[c].checked==true)
actualchoices[q]=thequestion[c].value
}
ETC...
问题是当我尝试做多项选择题时,我尝试使用这个但仍然失败:
<div class="qheader">
1) What is the difference between a jungle and a rain forest?</div>
<div class="qselections">
<input type="checkbox" value="a" name="question1">a) No difference. Simply two different ways in referring to the same thing.<br>
<input type="checkbox" value="b" name="question1">b) A jungle in general receives less rain than a rain forest.<br>
<input type="checkbox" value="c" name="question1">c) A jungle refers to the thickest area of a rain forest<br>
<input type="checkbox" value="d" name="question1">d) A jungle and a rain forest each contain their own group of distinct plants and animals.<br>
</div>
或者
<div class="qheader">
1) What is the difference between a jungle and a rain forest?</div>
<div class="qselections">
<input type="checkbox" value="a" name="question1[]">a) No difference. Simply two different ways in referring to the same thing.<br>
<input type="checkbox" value="b" name="question1[]">b) A jungle in general receives less rain than a rain forest.<br>
<input type="checkbox" value="c" name="question1[]">c) A jungle refers to the thickest area of a rain forest<br>
<input type="checkbox" value="d" name="question1[]">d) A jungle and a rain forest each contain their own group of distinct plants and animals.<br>
</div>