Em có một list câu hỏi và thực hiện hiện thị lần lượt từng câu… khi trả lời xong thì click next để sang câu tiếp theo… và có thể quay lại trả lời…
em đã là ngon chỗ next nhưng với button back thì lại đang lỗi tung lên
htmlArr.push('<div class="question-list">');
surveyObj.listQuestion.forEach(question=>{
htmlArr.push('<div id="'+question.questionId+'" class="question">');
htmlArr.push('<h3>'+question.content+'</h3>');
htmlArr.push('<div style="display:none;" id="'+question.answerType+'" class="answerType-'+question.questionId+'"> assd</div>');
htmlArr.push('<span id="err-'+question.questionId+'" style="color:red; display:none;" >Không thể để trống đáp án</span>');
console.log(question.answerType);
htmlArr.push('<div class="answer-list">');
question.listAnswer.forEach(answer=>{
htmlArr.push('<div class="answer" id="'+answer.answerId+'">');
htmlArr.push('<input type="radio" id="answerId-'+answer.answerId+'" name="questionId-'+question.questionId+'" class="answer-input" data-id="'+answer.answerId+'" value="'+answer.answerId+'" >');
htmlArr.push('<label for="answer-'+answer.answerId+'">'+answer.content+'</label>');
htmlArr.push('</div>');
});
htmlArr.push('</div>');
htmlArr.push('</div>');
}
htmlArr.push('</div>');
htmlArr.push('</div>');
htmlArr.push('<button class="btn btn-success btn-next" type="button" data-index="0">Tiếp theo</button>');
htmlArr.push('<button class="btn btn-success btn-back" type="button" style="display:none;" >Quay lại</button>');
htmlArr.push('<button class="btn btn-success btn-finish" type="button" style="display:none;">Hoàn thành</button>');
đây là function khi click button quay lại
jQuery('#survey').find('.btn-back').click(function(){
jQuery('.question-list .question').hide();
jQuery('#survey .btn-finish').hide();
var index = parseInt(jQuery('.btn-next').attr('data-index'));
jQuery('.btn-next').attr('data-index', index - 1);
console.log(index);
if(index <= 0){
index=0;
jQuery('.btn-next').attr('data-index', index);
jQuery('#survey .question-list .question').eq(index).show();
jQuery('#survey .btn-next').show();
jQuery('#survey .btn-back').hide();
}else{
jQuery('#survey .question-list .question').eq(index).show();
jQuery('#survey .test-result').hide();
jQuery('#survey .btn-next').show();
jQuery('#survey .btn-back').show();
}
});