코드를 단축하고 싶습니다. 나는 퀴즈를 가지고 있으며 각 질문마다 대답이 적재됩니다. 그러나 나는 그것을 위해 변수를 갖고 싶다. 여기 변수를 JSON 키로 사용하십시오.
코드입니다 :if (nr === 1) {
$('#questionmobile').html(content.inst3.question1);
$('#answer1').html(content.inst3.q1a1);
$('#answer2').html(content.inst3.q1a2);
$('#answer3').html(content.inst3.q1a3);
$('#answer4').html(content.inst3.q1a4);
} else if (nr === 2) {
$('#questionmobile').html(content.inst3.question2);
$('#answer1').html(content.inst3.q2a1);
$('#answer2').html(content.inst3.q2a2);
$('#answer3').html(content.inst3.q2a3);
$('#answer4').html(content.inst3.q2a4);
}......
당신은 매우 중복 볼 수 있듯이, 그래서 나는 질문의 수의 정보가 변수 "NR"를 포함하는 생각. 그것은 바로 JSON의 콘텐츠를 직접하지 않습니다 때문에 연결 +nr+
가 작동하지
$('#questionmobile').html(content.inst3.question+nr);
$('#answer1').html(content.inst3.q+nr+a1);
: 그래서 내가 좋아하는 뭔가를 원한다.