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

3 回答 3

0

你的输出应该是相反的:

//output
document.getElementById('BAC').value = BAC;

此外,您尝试在内部执行的所有乘法都document.getElementById应该在外部进行。例如:

var beer = document.getElementById("beer").value  * .54;
于 2013-09-19T19:30:14.720 回答
0

试试这条线

document.getElementById("BAC").value = BAC; //notice "BAC" instead of BAC, you're trying to grab the element that doesn't exist
于 2013-09-19T19:31:08.003 回答
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

根据您的代码,您的输出将是输入控件的值。

于 2013-09-19T19:31:23.870 回答