我的Javascript已關閉。我是一名初學者。 我在三個表單域中輸入三個數字。加法工作,但不是乘法。也會喜歡平均功能。這是代碼。JavaScript乘以3整數
<!DOCTYPE html>
<html>
<body>
<pre>
<form>
NUMBER1:
<input type="text" id="firstNumber" maxlength="100" size="20">
<br>
NUMBER2:
<input type="text" id="secondNumber" maxlength="100" size="20">
<br>
NUMBER3:
<input type="text" id="thirdNumber" maxlength="100" size="20">
<br><br>
<input name="Calculate Total" type="button" onclick="calculateText();" value="Add Total">
<input type="text" id="Total" maxlength="100" size="20">
<input name="Multiply Total" type="button" onclick="calculateText();" value="Multiply Total">
<input type="text" id="multiplyresult" maxlength="100" size="20">
</form>
</body>
</html>
function calculateText(){
var number1=document.getElementById('firstNumber');
var number2=document.getElementById('secondNumber');
var number3=document.getElementById('thirdNumber');
var result=document.getElementById('Total');
var multiplyresult=document.getElementById('multipyTotal');
var multiplyresult= number1 * number2 * number3;
if(number1.value=="" || number1.value!=parseFloat(number1.value)) number1.value=0;
if(number2.value=="" || number2.value!=parseFloat(number2.value)) number2.value=0;
if(number3.value=="" || number3.value!=parseFloat(number3.value)) number3.value=0;
result.value=0;
result.value=parseInt(result.value);
result.value=parseInt(result.value)+parseInt(number1.value)+parseInt(number2.value)+parseInt(number3.value);
}
而在一個的jsfiddle:http://jsfiddle.net/kamull61/2shG3/
爲什麼你會希望能夠乘** **輸入ALA'NUMBER1 * NUMBER2 * number3'但必須添加自己的** **數值ALA'parseInt函數(number1.value)+ parseInt函數(NUMBER2 .value)+ parseInt(number3.value)'?從那裏開始... – kaveman