cell2.textContent = question.isCorrect ? question.question.slice(1) : question.question.slice(1)+'<button onclick="chongzuo(question.question)" style="width: 100%; height: 90px; font-size: 40px;">重做错题</button>';
1、加在后面,怎么是一串原代码,不是按纽
2、想在错题后面加一个“重做错题”按纽,点击这个按纽就进入到做题那个页面,把题重新做一次
做题页面:
<script language="javascript">
/*.............省略............*/
function generateQuestion() {
let result = 0;
const operators = ['+', '-'];
let question = '';
let lastOperator = '+'; // 初始操作符为加号
let lastNumber = null; // 初始化上一个数字为null
let buttonsDisabled = true; // 按钮初始状态为不可点击
if(type==7)
{
if(bishu==2)
{
bishu=3;
}
}
for (let i = 0; i < bishu; i++) {//这里是随机显示数字,现在想要循环错题,要怎么弄
let number, operator;
let validNumber = false;
let result_onesDigit=onesDigit(result);
// 循环直到找到一个合适的数字
do {
if(type==1)//1-4直加直减
{
number = Math.floor(Math.random() * 4) + 1; // 1-4的随机数
operator = operators[Math.floor(Math.random() * 2)];
// 检查当前操作符和数字是否会导致结果超出范围
if (operator === '+') {
validNumber = result + number <= 4;
}
else
{
validNumber = result - number >= 0;
}
}
// 检查新数字和操作符与上一个数字和操作符是否不同
if (lastNumber !== null && (number === lastNumber || (lastOperator === operator && number === lastNumber))) {
validNumber = false;
}
} while (!validNumber);
lastOperator = operator; // 更新上一个操作符
lastNumber = number; // 更新上一个数字
setTimeout(() => {
displayQuestion(number,'','');
}, (i + 1) * shijian*1000);//间隔时间*1000
result += operator === '+' ? number : -number;
question += (i > 0 ? ' ' : '') + operator + number;
}
if(xingshi==1 || xingshi==2)
{
setTimeout(() => {
document.getElementById('question').textContent = '请答题';
isQuestionDisplayed = true; // 在显示“请答题”后将标志设为true
}, shijian*bishu*1000+1000);
}
else
{
let yanshi=shijian*1000+1000+1000*1.5*bishu-300*bishu*yusu/4;
setTimeout(() => {
document.getElementById('question').textContent = '请答题';
isQuestionDisplayed = true; // 在显示“请答题”后将标志设为true
}, yanshi);
}
questions.push({ question: question, answer: result });
}
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;
}
if(tiliang==1)
{
if (currentQuestionIndex < zushu-1) {//几道题
currentQuestionIndex++;
document.getElementById('question').textContent = '';
generateQuestion();
} else {
let endTime = new Date().getTime(); // 记录结束时间
let totalTime = (endTime - startTime) / 1000; // 转换为秒
localStorage.setItem('questionsData', JSON.stringify(questions));
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();
}
if(xingshi==1 || xingshi==2)
{
document.getElementById('question').textContent = '请看题';
}
else
{
document.getElementById('question').textContent = '请听题';
speak1('请听题');
}
}
if(tiliang==1)
{
// 初始化第一题
generateQuestion();
}
else
{
// 初始化答题系统
function initQuizSystem() {
generateQuestion(); // 初始化第一题
startTimer(zushu * 60 * 1000); // 开始10分钟计时
}
// 在页面加载完成后初始化答题系统
window.onload = initQuizSystem;
}
</script>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr class="STYLE2">
<td height="600" colspan="3" align="center" valign="middle" style="font-size: 300px;"><div id="question">{if $xingshi eq 1 or $xingshi eq 2}请看题{else}请听题{/if}</div><div id="question1"></div><input type="hidden" name="answerInput" id="answerInput" placeholder="输入答案"></td>
</tr>
<tr class="STYLE2">
<td align="center" valign="middle" style="font-size: 300px;">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr class="STYLE2">
<td width="25%" height="90" align="center"><button onclick="shuzi(1)" style="width: 100%; height: 90px; font-size: 40px;">1</button></td>
<td width="25%" align="center"><button onclick="shuzi(2)" style="width: 100%; height: 90px; font-size: 40px;">2</button></td>
<td width="25%" align="center"><button onclick="shuzi(3)" style="width: 100%; height: 90px; font-size: 40px;">3</button></td>
<td width="25%" align="center"><button onclick="shuzi(0)" style="width: 100%; height: 90px; font-size: 40px;">0</button></td>
</tr>
<tr class="STYLE2">
<td height="90" align="center"><button onclick="shuzi(4)" style="width: 100%; height: 90px; font-size: 40px;">4</button></td>
<td align="center"><button onclick="shuzi(5)" style="width: 100%; height: 90px; font-size: 40px;">5</button></td>
<td align="center"><button onclick="shuzi(6)" style="width: 100%; height: 90px; font-size: 40px;">6</button></td>
<td align="center"><button onclick="shuzi('qingchu')" style="width: 100%; height: 90px; font-size: 40px;">清除</button></td>
</tr>
<tr class="STYLE2">
<td height="90" align="center"><button onclick="shuzi(7)" style="width: 100%; height: 90px; font-size: 40px;">7</button></td>
<td align="center"><button onclick="shuzi(8)" style="width: 100%; height: 90px; font-size: 40px;">8</button></td>
<td align="center"><button onclick="shuzi(9)" style="width: 100%; height: 90px; font-size: 40px;">9</button></td>
<td align="center"><button onclick="checkAnswer()" style="width: 100%; height: 90px; font-size: 40px;">{if $zushu eq 1 and $tiliang eq 1}看答案{else}下一题{/if}</button></td>
</tr>
</table>
</td>
</tr>
</table>