<!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>
&#13;
我正在尝试使用带有输入的html和javascript输入框(正数,可以是小数但只能到第100位)我让网页工作到需要整数的位置将其添加到硬编码的数字并显示输出&#34; hard_coded_number + input_number = output_number&#34;
答案 0 :(得分:1)
我所要做的就是将parseInt改为parseFloat,它对我有用