HTML 实现BMI测试


<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>input输入框title>
head>
<body>
    <label for="high">身高label>
    
    <br>
    <br>
    <label for="weight">体重label>
    
    <br>
    <br>
    <button onclick="btnClink()">点击查看您的BMIbutton>
body>
<script>
    function btnClink()
    {
      
        var input1 = document.getElementById("high");
        var input2 = document.getElementById("weight");
        var shengao = input1.value / 100;
        var tizhong = input2.value / 2;
        var res = tizhong / shengao / shengao;
        res = res.toFixed(2);
        if(res <= 18.4)
        {
      
            alert("BMI = " + res + " " + "偏瘦," + " 多吃肉");
        }
        else if(res >= 18.5 && res <= 23.9)
        {
      
            alert("BMI = " + res + " " + "正常," + " 继续保持");
        }
        else if(res >= 24.0 && res <= 27.9)
        {
      
            alert("BMI = " + res + " " + "偏重," + " 多运动");
        }
        else
        {
      
            alert("BMI = " + res + " " + "肥胖," + " 多多运动");
        }
    }    
script>
html>

你可能感兴趣的:(HTML5)