javascript - 我试图建立一个网站,javascript数学不起作用
问题描述
我正在尝试使用 codepen.io 制作一个网站来销售东西(不是真正的“销售”东西),但由于某种原因,使用 javascript 的计算不起作用,我试图让它计算总数和将其显示在文本字段中。这是javascript。
function doFunction(){
var shirtNo, bearNo, pillowNo, totalNo;
var shirtNo = document.getElementById("panda_shirt").value;
bearNo = document.getElementById("panda_toy").value;
pillowNo = document.getElementById("panda_pillow").value;
var totalQty = panda_shirt + panda_toy + panda_pillow ,
estimateTotal;
estimateTotal = ($14 * panda_shirt) + ($12 * panda_toy) + ($10 *
panda_pillow);
document.getElementById('estimateTotal').value = Estimate Total;
}
解决方案
'$14' is not a number.
computers are perfect at math. that's their primary function. so if the math is wrong, it's your code, not the computer or the language.
also you have not defined panda_shirt
or your other variables, so it appears you are attempting to do math with undefined objects.
try adding console.log()
statements to your code so you can see what variable values you are dealing with.
推荐阅读
- node.js - 如果两个用户来自两个不同的表,则反应基于角色的身份验证
- reactjs - 在 safari 中长时间使用后 React App 变慢
- javascript - 水付计算器 else if 语句
- php - laravel 关系返回 null
- python - 我可以跨同一个 python 包的模块重用导入吗?
- java - 如何向现有 Firebase 数据库条目添加新子项?
- javascript - 错误:Route.put() 需要回调函数,但得到了 [object Undefined]
- mysql - 如何在mysql命令中的longtext类型的列中插入初始值
- excel - 尝试使用 VBA 复制并粘贴到另一个工作表,但是当它粘贴时它只是粘贴空白
- angular - 更新库 ng2-tooltip-directive 时出错