0
<html>
<head><title>One rep max</title>
<script type="text/javascript">
function calculateOneRepMax(){
var p = document.getElementById("button");
p.onclick = showAlert;
}
function showAlert(){
var weight = document.getElementById("weight").value;
var reps = document.getElementById("reps").value;
var orm = ((weight * reps)/ 30) + weight;
alert(orm);
}
</script>
</head>
<body onload="calculateOneRepMax()">
<form>
Weight: <input type="text" id="weight"/><br>
Reps: <input type="text" id="reps" /><br>
<input id="button" type="button" value="Calculate" onClick="calculateOneRepMax()" />
</form>
</body>
</html>
我想用这个公式创建一个计算器,用于举重的一个最大值。 (Weight * Reps)/30 + Weight
。为什么我没有得到正确的价值?
问题在于脚本没有在(Weight * Reps)/30
之后添加权重。
这里有什么问题?
为什么你有事件触发onload onload?点击你的按钮后,你是不是只希望它计算? onload会尝试运行没有值......因为在执行时没有任何html集 – markS