window.onload = function() {
const questionsData = JSON.parse(localStorage.getItem('questionsData'));
const resultsTableBody = document.getElementById('resultsTableBody');
let correctCount = 0;
let wrongCount = 0;
// 计算对错题数
questionsData.forEach(question => {
if (question.isCorrect) {
correctCount++;
} else {
wrongCount++;
}
});
// 更新段落文本
const summaryElement1 = document.getElementById('summary1');
const summaryElement2 = document.getElementById('summary2');
summaryElement1.textContent = `${correctCount}`;
summaryElement2.textContent = `${wrongCount}`;
questionsData.forEach((question, index) => {
const row = resultsTableBody.insertRow();
const cell1 = row.insertCell(0);
const cell2 = row.insertCell(1);
const cell3 = row.insertCell(2);
const cell4 = row.insertCell(3);
// 添加class到每个cell
cell1.className = "biankuan4";
cell2.className = "biankuan5";
cell3.className = "biankuan5";
cell4.className = "biankuan5";
cell1.textContent = index + 1;
cell2.textContent = question.question;
cell3.textContent = question.userAnswer;
cell4.textContent = question.isCorrect ? '√' : '×';
});
};
怎么让:如果提交的答案是错误的,则把正确的答案显示在错误的旁边:cell3.textContent = question.userAnswer+‘【‘+正确答案+’】’;