我尝试制作测验/考试申请表。我没有创建单选题的问题(我的引用来自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
}
等...
问题是,当我尝试做出多项选择问题时,我尝试使用这个但仍然失败了:
<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>
答案 0 :(得分:0)
您应该使用checkboxes names
之类的question1,question2,question3,....
<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="question2">b) A jungle in general receives less rain than a rain forest.<br>
<input type="checkbox" value="c" name="question3">c) A jungle refers to the thickest area of a rain forest<br>
<input type="checkbox" value="d" name="question4">d) A jungle and a rain forest each contain their own group of distinct plants and animals.<br>