我正在使用jQuery创建一个测验。我知道这不是一项非常困难的任务,但我似乎遇到了以下问题: (a)读取多维数组的值,即问题的答案,即数组的元素[0] 和 (b)在我的html中出现的单选按钮后显示这些值。
这是我在HTML中的内容
<!--practice quiz-->
<div id="practiceQuestions">
<div class="questionBox">
<div class="theQuestion">
<span id="quizQuestion"><img src="images/Practice_Tips_Math.png"></span>
<INPUT type="submit" value="Start quiz now" id="startQuiz" class="viewable">
<!--answer key beginsb-->
<div class="answerBox">
<form name="answerForm">
<input type="radio" value="a" id="answerA" name="quizAnswer"><br />
<input type="radio" value="b" id="answerB" name="quizAnswer"><br />
<input type="radio" value="c" id="answerC" name="quizAnswer"><br />
<input type="radio" value="d" id="answerD" name="quizAnswer"><br />
<input type="radio" value="e" id="answerE" name="quizAnswer"><br />
</form></div>
<!--answer key end-->
</div>
</div>
</div>
<!--practice quiz ends-->
这就是我在jQuery中的内容
var question=[
['How many moons does Earth have?',1,2,3,4,5],
['How many moons does Saturn have?',31,32,33,34,35],
['How many moons does Venus have?', 0,1,2,3,4]
];
function askQuestion(question){
if($('#startQuiz').is(':visible')) {
$('#startQuiz').toggle();
}
if($('.answerBox').is(':hidden')) {
$('.answerBox').toggle();
$('.answerBox').css('margin-top','50px');
}
$(".theQuestion").css('margin-top','75px');
$("#quizQuestion").text(question[0]);
//want the answers from question array to appear here from question[i]
$('#answerA').text(question[1]);
$('#answerB').text(question[2]);
$('#answerC').text(question[3]);
$('#answerD').text(question[4]);
$('#answerE').text(question[5]);
};
$(document).ready(function(){
$('#startQuiz').on('click',function(){
for (var i=0; i<=question.length; i++)
{
askQuestion(question[i]);
}
});
});