0
选择是在json对象中的嵌套数组我选择这个数据为多选测验序列。 当我按功能触发器控制台说'未捕获TypeError:无法读取属性的'选择'的未定义'我也有一个变量'c',当用户选择另一个考试,所以语句考试=考试+ c将无法安置功能的工作。错误与JSON未捕获TypeError:无法读取未定义的属性'选择'
var exam0 = [
{
"question": "which is a negative number?",
"choices": [
"2",
"-2",``
"6",
"8",
],
"correctAnswer": "B",
"hint": "The one with the ' - ' negative sign"
},
......other questions****
];
功能是
function placement(x) /*x is variable used to change the question from the json object*/
{
choiceOne=$('<p>').text('A.'+exam[x].choices[0]); /*where the console points to problem*/
choiceTwo=$('<p>').text('B.'+exam[x].choices[1]);
choiceThree=$('<p>').text('C.'+exam[x].choices[2]);
choiceFour=$('<p>').text('D.'+exam[x].choices[3]);
currentQuestion=$('<p>').text(exam[x].question);
$("#honeyPot").empty().append(currentQuestion);
$("#honeyPot p").prepend(count+".");
$('#options').find('p').remove().hide();
$('#optionOne').fadeIn(250).append(choiceOne);
$('#optionTwo').fadeIn(250).append(choiceTwo);
$('#optionThree').fadeIn(250).append(choiceThree);
$('#optionFour').fadeIn(250).append(choiceFour);
}
您正在定义'exam0',但'placement'函数引用'exam'。它看起来并不像任何地方定义“考试”。 – sherb 2014-11-07 03:10:34