나는 다차원 배열의 요소를 동적으로 인쇄하여 퀴즈를 작성하는 자바 스크립트 프로그램을 작성 중입니다. 내 구조는 정확하지만 '선택'요소를 인쇄하여 각 질문의 선택을위한 라디오 버튼으로 표시하려고합니다.for 루프를 사용하여 다차원 배열 요소를 동적으로 인쇄
자바 스크립트 :
이var dataquestions = [];
dataquestions[0] = {question: "Who is the prime Minister of the United Kingdom?", choice0: "David Cameron", choice1: "Tony Blair", choice2:"Gordon Brown", answer:"David Cameron"};
dataquestions[1] = {question:"In what year was the Declaration of Independence signed?", choice0:"1985", choice1:"1492", choice2:"1776", answer:"1776"};
dataquestions[2] = {question:"Which country is in Europe?", choice0:"Pakistan", choice1:"France", choice2:"Australia", answer:"France"};
for (var i=0; i<=2; i++)
{
document.getElementById('quizcontain').innerHTML+= '<p>'+ dataquestions[i].question+'</p><br><br>';
for (var j=0; j<=2; j++){
document.getElementById('quizcontain').innerHTML+='<input type="radio" name='+j+'>'+dataquestions[i].choice+j+'<br>';
}
}
출력 :
Who is the prime Minister of the United Kingdom?
undefined
undefined
undefined
In what year was the Declaration of Independence signed?
undefined
undefined
undefined
Which country is in Europe?
undefined
undefined
undefined
완벽하게 일했다! 고맙습니다! –
@ JeffP. 당신은 환영합니다 :)이 대답을 틱하지 않는 것을 잊지 마십시오 :) – thefourtheye
니스, @thefourtheye. – zee