2016-12-06 34 views
0

的Javascript文本框中輸入和簡單的數學

<!DOCTYPE html> 
 
<html> 
 
<body> 
 
Please enter a number:<BR> 
 
<input type="text" id="amount_input"> 
 
<button onclick="other_amount_input()">Submit</button> 
 
<script> 
 
var balance=502.73; 
 
function other_amount_input() { 
 
    var input = document.getElementById("amount_input").value; 
 
    var new_total = parseInt(input) + balance; 
 
    alert("The amount deposited is: $" + input + ".00\n" + "This is the old balance: $" + balance + "\n" + "The new total is : $" + new_total); 
 
} 
 
</script> 
 
</body> 
 
</html>

我試圖讓HTML和JavaScript,其採用輸入(正數的輸入框,可以是一個小數,但只起到第100地方)我有網頁工作到哪裏將採取一個整數,並將其添加到一個硬編碼的數字,並顯示「hard_coded_number + input_number = output_number」的輸出

+0

你的問題是什麼?當你弄清楚它是什麼時,可能將代碼作爲可運行代碼片段發佈? – RobG

回答

0

我所要做的就是將parseInt更改爲parseFloat它爲我工作

相關問題