这是我使用的 Html 形式。
<form name="calculate" method="get" action="#" onsubmit="return Validate()">
<label>Enter a number</label>
<input id="numb1" name="numb1" id="numb2" placeholder="Number 1">
<label>Enter another number</label>
<input id="numb2" name="numb2" id="numb2" placeholder="Number 2">
<label>Result</label>
<textarea style="text-align:center; height:85px; max-height:85px;" name="summ" id="summ" disabled="disabled" placeholder="Result" dir="ltr"></textarea>
<br />
<input id="calc" name="calc" type="submit" value="Calculate!">
JS
function Validate() {
if (calculate.numb1.value == "" || calculate.numb2.value == "") {
alert("Check the form again");
calculate.numb1.focus();
document.getElementById('summ').value = "";
return (false);
}
Update()
return (true);
}
function Update() {
var plus = calculate.numb1.value + calculate.numb2.value;
var minus = calculate.numb1.value - calculate.numb2.value;
var mult = calculate.numb1.value * calculate.numb2.value;
var div = calculate.numb1.value / calculate.numb2.value;
var multi = document.getElementById("summ").value = calculate.numb1.value + "+" + calculate.numb2.value + "=" + plus + "\n" + calculate.numb1.value + "-" + calculate.numb2.value + "=" + minus + "\n" + calculate.numb1.value + "*" + calculate.numb2.value + "=" + mult + "\n" + calculate.numb1.value + "/" + calculate.numb2.value + "=" + div;
}
所有计算都完全接受 Plus 功能。例如,当您键入 4+4 时,您会得到 44... 我尝试了 parseFloat,但仍然没有任何变化。