爲什麼在for循環迭代第一個應答對象數組後,click方法返回undefined?jQuery click方法在迭代嵌套在另一個數組中的嵌套對象時返回undefined
var i = 0;
var j = 0;
var allQuestions = [{question:"What is the color of the sky?",answer:["blue","yellow",
"red"],correctAnswer:["blue",1]},{question:"What is the opposite of
up?",answer:["down","sideways", "circle"],correctAnswer:["down",1]},
{question:"What is the first number?",answer:["1","5", "7"],correctAnswer:
["1",1]}];
$(document).ready(function() {
function changeQuestion() {
$("#radios").empty();
for(answers in allQuestions[i].answer) {
var radioBtn = $('<input type="radio" class="radios" name="btnAnswers" value="'+
allQuestions[i].answer[j] + '" /><label for ="secondbtn">'
+ allQuestions[i].answer[j] + '</label>');
radioBtn.appendTo('#radios');
alert(allQuestions[i].answer[j]);
j++;
}
i++;
return true;
};
$("#nextbtn").click(function(){
changeQuestion();
});
});
'i'和'j'初始化在哪裏? –
@ Roamer-1888對不起,沒有在最初的帖子中添加它們。他們現在在那裏,但仍然無法工作。 – Stu