<!DOCTYPE html>
<html>
<meta content="text/html; charset=utf-8">
<head>
<title>BAC Calculator</title>
//表单为我的html页面。不确定使用提交的天气或只是这种类型的按钮。如果退货表格是正确的还是正确的。
<form action="" onSubmit="return formbac()" id="formbac">
Weight:<input id="weight" name="weight1" type="number">
Beer:<input id="beer" name="beer1" type="number">
Wine:<input id="wine" name="wine1" type="number">
Shots:<input id="shots" name="shots1" type="number">
Time:<input id="time" name="time1" type="number">
<input name="submit" type="submit" value="Calculate">
<hr>
BAC: <input type="" name="bac" id="BAC">
</form>
</head>
<body>
//用于计算的Javascript代码 我认为这是正确的,但我可能会将代码与我的计算混合//
<script>
//基本功能
function formbac(){
//values
var weight = document.getElementById("weight").value;
var beer = document.getElementById("beer" * .54).value;
var wine = document.getElementById("wine" * .6).value;
var shots = document.getElementById("shots" * .6).value;
var time= document.getElementById("time").value;
var BAC = 0;
//尝试获取baclevels的输出
// calculations
var BAC = ((beer + wine + shots * 7.5) / (weight * .68)) - (0.015 * time);
//decimal round
var BAC = math.round(bac*100)/100;
//output
var BAC = document.getElementById(BAC).value;
}
</script>
</body>
</html>
答案 0 :(得分:0)
您的输出应该是相反的方式:
//output
document.getElementById('BAC').value = BAC;
此外,您尝试在document.getElementById
内执行的所有乘法都应该在外面。例如:
var beer = document.getElementById("beer").value * .54;
答案 1 :(得分:0)
请尝试使用此行
document.getElementById("BAC").value = BAC; //notice "BAC" instead of BAC, you're trying to grab the element that doesn't exist
答案 2 :(得分:0)
// calculations
var BAC = ((beer + wine + shots * 7.5) / (weight * .68)) - (0.015 * time);
//decimal round
var BAC = math.round(bac*100)/100; //override above value
//output
var BAC = document.getElementById(BAC).value; //override above value
根据您的代码,您的输出将是输入控件的值。