为了计算身体质量指数,我有这个 javascript,其中有两个用于身高和体重的输入字段和一个用于显示计算输出的输入字段。
如何在 BMI 字段中自动显示 che calc?
商标
<h2>Height=<input type="text" id="hgt"></h2>
<h2>Weight=<input type="text" id="wgt" onmouseout="bmi()"></h2>
<h2>BMI=<input type="text" id="student_bmi">
Javascript
<script>
function bmi(){
var sheight=parseFloat(document.getElementById('hgt').value);
var sweight=parseFloat(document.getElementById('wgt').value);
var bmi=sweight/Math.pow(sheight,2);
var student_bmi=document.getElementById('student_bmi').value;
student_bmi.textContent=bmi.toFixed(2);
}
</script>
在 Height 和 Weight 字段中插入值后,不会在 BMI 字段中显示计算值。
如何解决这个问题?
慕尼黑5688855
相关分类