【发布时间】:2016-06-27 19:54:47
【问题描述】:
这是我的 js 函数。当我输入数据时,我得到 NaN
//BMI is defined as BMI = ( Weight in Pounds / ( Height in inches x Height in inches ) ) x 703
function calculatebmi(weight, height){
//window.alert("hello");
var weight = parseInt(document.getElementsByName("weight_pounds"));
var height = parseInt(document.getElementsByName("height_inches"));
var bmi = parseInt(((weight/height)*703));
window.alert("your BMI is: " + bmi);
}
我已经尝试过 math.floor 和 innerHTML。两者都没有帮助。
输入标签类型是数字,以防有人想知道。
【问题讨论】:
-
您的 BMI 公式错误。你需要取高度的平方。
-
哇。两个基本错误的独特组合,第一个是没有意识到
getElementsbyName会产生一个节点列表,您必须采用第一个元素(为什么要使用名称而不是 ID?),第二个是不记得采用使用其value属性的元素的值。
标签: javascript html nan