我正在做一个小项目,其中包含一个php页面,它将要求用户输入测试的问题数量,在写完一个数字后,例如10,他将为每种类型的考试分配问题的数量(加法,减法,乘法,除法),直到问题的数量结束,例如,在选择10个问题后,他可以选择5,另外3个乘法和2个除法,但他不能再分配问题,因为10个总问题已经完成。他将这些数字分配到html中的数字输入类型中,因此我希望获得第一个输入类型,即问题的总数,然后每次他增加任何考试类型(加法,..)时,递减该数字。当它达到0时,它将禁用输入类型,这是我到目前为止所做的:
var numInput = document.getElementById('numInput');
var Input1 = document.getElementById('Input1');
var Input2 = document.getElementById('Input2');
var Input3 = document.getElementById('Input3');
var Input4 = document.getElementById('Input4');
Input1.disabled = true;
Input2.disabled = true;
Input3.disabled = true;
Input4.disabled = true;
var Checker = setInterval(function Checker() {
var numValue = numInput.value;
//thats what I tried to do to solve my problem but it didn't work properly because it must decrement only 1 but the condition will still be true so it will decrement for ever or at least that is what I think.
if (Input1.value > 0) {
numValue = numValue - 1;
}
//and this part is working fine.
if (numValue > 0) {
Input1.disabled = false;
Input2.disabled = false;
Input3.disabled = false;
Input4.disabled = false;
} else if (numValue <= 0) {
Input1.disabled = true;
Input2.disabled = true;
Input3.disabled = true;
Input4.disabled = true;
}
}, 100);
<form method="GET" action="">
<h2>How many questions do you want to answer?</h2>
<input id="numInput" type="number" name="Text" value="0" min="0"><br>
<h2>Addition: </h2> <input id="Input1" type="number" name="Text" value="0" min="0"><br>
<h2>Subtraction: </h2> <input id="Input2" type="number" name="Text" value="0" min="0"><br>
<h2>Multiplication: </h2> <input id="Input3" type="number" name="Text" value="0" min="0"><br>
<h2>Division: </h2> <input id="Input4" type="number" name="Text" value="0" min="0">
</form>
我不知道如何才能解决这个问题,所以请帮助我。
https://stackoverflow.com/questions/53749677
复制相似问题