<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
<style> | |
*{ | |
margin: 0;padding: 0; | |
} | |
.box{ | |
width: 400px; | |
height: 300px; | |
margin: 200px auto; | |
line-height: 50px; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="box"> | |
<h1>体质指数(BMI)</h1> | |
<p>请输入身高:<input type="text"></p> | |
<p>请输入体重:<input type="text"></p> | |
<button>开始检测</button> | |
<h4></h4> | |
</div> | |
<script> | |
var h = document.getElementsByTagName('h1')[0]; | |
var H = document.getElementsByTagName('h4')[0]; | |
var oP = document.getElementsByTagName('p'); | |
var btn = document.getElementsByTagName('button')[0]; | |
btn.onclick = function(){ | |
//身高: | |
var a = oP[0].value / 100; | |
//体重 | |
var b = oP[1].value; | |
//体质 | |
var c = b / (a*a); | |
if ( c < 18.5 ){ | |
console.log(txt = '过轻') | |
} | |
else if( 18.5 < c < 23.9 ){ | |
console.log(txt = '正常') | |
} | |
else if( 24 < c < 27 ){ | |
console.log(txt = '轻度肥胖') | |
} | |
else if( 28 < c < 32 ){ | |
console.log(txt = '肥胖') | |
} | |
else if( c > 32 ){ | |
console.log(txt = '重度肥胖') | |
} | |
H.innerHTML = txt; | |
} | |
</script> | |
</body> | |
</html> |
体脂的检测
最新推荐文章于 2024-01-25 14:32:49 发布