<!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 制作一个输入框,该输入框接受输入(正数,可以是小数,但只能到第一百位)我让网页工作到需要整数的地方将其添加到硬编码数字并显示输出“hard_coded_number + input_number = output_number”
最佳答案
我所要做的就是将 parseInt 更改为 parseFloat,它对我有用
关于Javascript文本框输入和简单数学,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40987962/