Javascript文本框输入和简单数学

标签 javascript html math textbox

<!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/

相关文章:

javascript - 如何在ajax中使用jquery get方法动态更改html

c++ - 围绕绝对轴旋转 3d 模型

math - 尝试理解 WebGL 中透视矩阵背后的数学原理

javascript - Javascript 中的 Windows 8 Metro SyndicateClient.retrieveFeedAsync 实际上不是异步的?

javascript - 菜单项 onclick 在悬停事件上调用多 css

c# - 使用 HTML 在 MVC 中提交表单

algorithm - 使用两个随机函数得到一个特定的随机函数

javascript - 自动刷新 Div 内容 - 无需 PHP

javascript - 加载微调器不适用于 Angularjs 中的 ng-click 或 ng-change

jquery - 如何停止将事件从父 div 传播到子 div