【发布时间】:2020-01-14 19:53:17
【问题描述】:
请帮助我,我已经完成了 javascript。只有最后一部分非常困难。 我使用了contact form7的计算器插件来计算BMI,这非常有效。 隐藏 BMIhigh 文本也可以,点击
Length (cm):
<label id="centi">[number* cm min:130 max: 220]</label>
Hight (kilo):
<label id="kilo">[number* kilo min:40 max:140]</label>
<label id="calcbutton">[calculate_button "calculate"]</label>
<label id="calc">[calculation calculate precision:1 "kilo / ((cm / 100) * (cm / 100))"]</label>
<label id="BMIhigh">
Your BMI is too high
</label>
[submit "Send"]
在底部我有以下代码:
// Hide the BMIhigh text field by default
document.getElementById("BMIhigh").style.display = 'none';
// On every 'click' on the calculator call the displayTextField function
document.getElementById("calcbutton").addEventListener("click", displayTextField);
function displayTextField() {
// Get the inserted values for centi and kilo and calculate the BMI again
// for the function without the help of the calculator build in into the extra plugin.
var centimeter = +document.getElementById("centi").value;
var kilogram = +document.getElementById("kilo").value;
var BMIvar = kilogram / ( ( centimeter / 100 ) * ( centimeter / 100 ) );
// If BMIvar higher than 30 it is too high, the text should show.
// THIS LAST PART DOES NOT WORK
if(BMIvar > 30) {
document.getElementById("BMIhigh").style.display = 'block';
} else {
document.getElementById("BMIhigh").style.display = 'none';
}
}
</script> ```
【问题讨论】:
-
您的问题含糊不清,尚不清楚您要达到的目标。请阅读问题guidelines,了解如何最大限度地提高获得帮助的机会。
-
我想要一个 BMI 计算器,当 BMI 高于 30 时,应该出现文本元素。只有代码的最后一部分不起作用。我不明白为什么。感谢您的帮助!
-
您是否尝试过使用debugger in the javascript console 单步执行您的代码?
标签: javascript wordpress contact-form-7