运算页:
function checkAnswer() {
if($.trim($("input[name=answerInput]").val()) == "")
{
$("input[name=answerInput]").focus();
return false;
}
document.getElementById('question1').textContent='';
isQuestionDisplayed = false;//每一题重新禁用按纽
const userAnswer = parseInt(document.getElementById('answerInput').value);
if (userAnswer === questions[currentQuestionIndex].answer) {
alert('正确!');
} else {
alert('错误,正确答案是: ' + questions[currentQuestionIndex].answer);
}
document.getElementById('answerInput').value = '';
$("input[name=answerInput]").focus();
if (userAnswer !== undefined) { // 确保 userAnswer 已被定义
questions[currentQuestionIndex].userAnswer = userAnswer; // 添加这一行
}
if (userAnswer === questions[currentQuestionIndex].answer) {
questions[currentQuestionIndex].isCorrect = true;
} else {
questions[currentQuestionIndex].isCorrect = false;
}
let endTime = new Date().getTime(); // 记录结束时间
let totalTime = (endTime - startTime) / 1000; // 转换为秒
localStorage.setItem('questionsData', JSON.stringify(questions));
if(tiliang==1)
{
if (currentQuestionIndex < jidaoti) {//几道题
currentQuestionIndex++;
document.getElementById('question').textContent = '';
generateQuestion(numbers);
} else {
if(numbers!='')
{
window.history.back();
}
else
{
window.location.href = "/oa/oa_zxsxl.php?act=jieguo&totalTime="+totalTime+"&type={$type}&type_text={$type_text}&xingshi={$xingshi}&xingshi_text={$xingshi_text}&tiliang={$tiliang}&zushu={$zushu}&bishu={$bishu}&shijian={$shijian}&yusu={$yusu}";
}
}
}
else
{
currentQuestionIndex++;
document.getElementById('question').textContent = '';
generateQuestion(numbers);
}
if(xingshi==1 || xingshi==2)
{
document.getElementById('question').textContent = '请看题';
}
else
{
document.getElementById('question').textContent = '请听题';
speak1('请听题');
}
}
成绩列表页:
html部分省略..............
<script>
window.onload = function() {
const questionsData = JSON.parse(localStorage.getItem('questionsData'));
const resultsTableBody = document.getElementById('resultsTableBody');
let correctCount = 0;
let wrongCount = 0;
// 对questionsData进行排序,错题在前,对题在后
questionsData.sort((a, b) => {
return a.isCorrect === b.isCorrect ? 0 : a.isCorrect ? 1 : -1;
});
// 计算对错题数
questionsData.forEach(question => {
if (question.isCorrect) {
correctCount++;
} else {
wrongCount++;
}
});
// 更新段落文本
const summaryElement1 = document.getElementById('summary1');
const summaryElement2 = document.getElementById('summary2');
const summaryElement3 = document.getElementById('summary3');
const summaryElement4 = document.getElementById('summary4');//准确率
let zts=correctCount+wrongCount;//总题数
let zql=correctCount/zts*100;
summaryElement1.textContent = `对题数:${correctCount}`;
summaryElement2.textContent = `错题数:${wrongCount}`;
summaryElement3.textContent = `总题数:${zts}`;
summaryElement4.textContent = `准确率:${zql.toFixed(2)}%`;
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);
const cell5 = row.insertCell(4);
// 添加class到每个cell
cell1.className = "biankuan2";
cell2.className = "biankuan3";
cell3.className = "biankuan3";
cell4.className = "biankuan3";
cell5.className = "biankuan3";
cell1.height = "40";
if (question.isCorrect) {} else {
cell1.style = 'color: crimson';
cell2.style = 'color: crimson';
cell3.style = 'color: crimson';
cell4.style = 'color: crimson';
cell5.style = 'color: crimson';
}
cell1.textContent = index + 1;
cell2.textContent = question.question.slice(1);
if (question.isCorrect) {} else {
cell2.innerHTML+=' <button onclick="chongzuo(\'' + question.question + '\')" style="height: 30px; font-size: 15px;"> 重做 </button>';
}
// 根据是否正确显示答案
cell3.textContent = question.userAnswer;
cell4.textContent = question.answer;
cell5.textContent = question.isCorrect ? '√' : '×';
});
};
function chongzuo(numbers) {
// 将题目信息编码并附加到URL
var encodedNumbers = encodeURIComponent(numbers); // 对numbers进行URL编码
window.location.href = '/oa/oa_zxsxl.php?act=yunsuan&type={$type}&type_text={$type_text}&xingshi={$xingshi}&xingshi_text={$xingshi_text}&tiliang={$tiliang}&zushu={$zushu}&bishu={$bishu}&shijian={$shijian}&yusu={$yusu}&numbers=' + encodedNumbers;
}
</script>
全部运算完以后进入到成绩列表页,这时会把所有做过的题全部列出来,然后算错的题后面有个重做按纽,点击重做后又进入到运算页,把错的题做一遍,做完这道错题后又进入到成绩列表,这时成绩列表只显示这一道错题,之前其它的题就没有显示了,于是我就做了一个判断,当是重做时,就window.history.back();返回到上一页,但是这样又有一个问题:这样返回去虽然保住了之前的其它所有题,但是我重做的最后结果没有更新。怎样能即保存之前的所有题,又能更新错题的结果。比如成绩列表页为:
序号 题目 我的答案 正确答案 是否正确
1 1+2+3【重做】 3 6 ×
2 3+2+3【重做】 5 8 ×
3 5-4+1 2 2 √
4 3-2+3 4 4 √
如果重做第一题后,如果答案还是不对,成绩列表页为:
序号 题目 我的答案 正确答案 是否正确
1 1+2+3【重做】 5 6 ×
2 3+2+3【重做】 5 8 ×
3 5-4+1 2 2 √
4 3-2+3 4 4 √
如果重做第一题后,如果答案对了,成绩列表页为:
序号 题目 我的答案 正确答案 是否正确
1 1+2+3 6 6 √
2 3+2+3【重做】 5 8 ×
3 5-4+1 2 2 √
4 3-2+3 4 4 √
接着做第二题,如果答案不对,成绩列表为:
序号 题目 我的答案 正确答案 是否正确
1 1+2+3 6 6 √
2 3+2+3【重做】 7 8 ×
3 5-4+1 2 2 √
4 3-2+3 4 4 √
接着做第二题,如果答案对了,成绩列表为:
序号 题目 我的答案 正确答案 是否正确
1 1+2+3 6 6 √
2 3+2+3 8 8 √
3 5-4+1 2 2 √
4 3-2+3 4 4 √