Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript和html中乘法表的延迟结果_Javascript_Html - Fatal编程技术网

javascript和html中乘法表的延迟结果

javascript和html中乘法表的延迟结果,javascript,html,Javascript,Html,函数设置数量(向上或向下){ num1=document.getElementById(“firstNumber”).value; num2=document.getElementById(“数量”).value; document.getElementById(“Inputresult”).value=num1*num2; var quantity=document.getElementById('quantity'); 如果(数量值>1){ if(upordown=='up'){++docu

函数设置数量(向上或向下){
num1=document.getElementById(“firstNumber”).value;
num2=document.getElementById(“数量”).value;
document.getElementById(“Inputresult”).value=num1*num2;
var quantity=document.getElementById('quantity');
如果(数量值>1){
if(upordown=='up'){++document.getElementById('quantity').value;}
else if(upordown=='down'){--document.getElementById('quantity').value;}
}
否则如果(quantity.value==1){
if(upordown=='up'){++document.getElementById('quantity').value;}
}
其他的
{
document.getElementById('quantity')。值=1;
}
}

数量:
结果是:


上面的代码部分应该在最后一部分,因为我们需要在递增后访问文本中的值

在递增数量之前设置结果,这会导致乘法不匹配。您需要切换代码,以便在设置结果之前对数量进行递增/递减操作。请看我的小提琴:()
<script>
    function setQuantity(upordown) {
   
    var quantity = document.getElementById('quantity');
    if (quantity.value > 1) {
        if (upordown == 'up'){++document.getElementById('quantity').value;}
        else if (upordown == 'down'){--document.getElementById('quantity').value;}
        }
    else if (quantity.value == 1) {
        if (upordown == 'up'){++document.getElementById('quantity').value;}
        }
    else
        {
        document.getElementById('quantity').value=1;
        }
    num1 = document.getElementById("firstNumber").value;
    num2 = document.getElementById("quantity").value;
    document.getElementById("Inputresult").value = num1 * num2;
}
</script>
num1 = document.getElementById("firstNumber").value;
    num2 = document.getElementById("quantity").value;
    document.getElementById("Inputresult").value = num1 * num2;