吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 703|回复: 18
收起左侧

[讨论] 给大家分享一下deepseek辅助制作的BMI 身体质量指数(计算器),html语言,

[复制链接]
lingdang07 发表于 2025-3-18 23:20
本帖最后由 lingdang07 于 2025-3-18 23:25 编辑

源码给大家分享一下
微信截图_20250318231624.png
具体实例:

微信截图_20250318232457.png 微信截图_20250318232448.png 微信截图_20250318232435.png

[HTML] 纯文本查看 复制代码
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>BMI 计算器</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f0f2f5;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        .calculator {
            background-color: #fff;
            padding: 30px;
            border-radius: 12px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            text-align: center;
            width: 320px;
        }
        h1 {
            color: #2c3e50;
            margin-bottom: 25px;
            font-size: 26px;
        }
        .input-group {
            margin: 15px 0;
            text-align: left;
        }
        label {
            display: block;
            color: #666;
            margin-bottom: 8px;
            font-size: 14px;
        }
        input {
            width: 100%;
            padding: 12px;
            border: 2px solid #e0e0e0;
            border-radius: 6px;
            font-size: 16px;
            box-sizing: border-box;
            transition: border-color 0.3s;
        }
        input:focus {
            border-color: #3498db;
            outline: none;
        }
        button {
            background-color: #3498db;
            color: white;
            border: none;
            padding: 12px 25px;
            border-radius: 6px;
            font-size: 16px;
            cursor: pointer;
            transition: background-color 0.3s;
            margin-top: 15px;
            width: 100%;
        }
        button:hover {
            background-color: #2980b9;
        }
        #result {
            margin-top: 25px;
            padding: 15px;
            border-radius: 6px;
            display: none;
        }
        .bmi-normal { background-color: #d4edda; color: #155724; }
        .bmi-over { background-color: #fff3cd; color: #856404; }
        .bmi-obese { background-color: #f8d7da; color: #721c24; }
        .error { background-color: #f8d7da; color: #721c24; }
    </style>
</head>
<body>
    <div class="calculator">
        <h1>BMI 身体质量指数计算器</h1>
         
        <div class="input-group">
            <label for="height">身高 (cm)</label>
            <input type="number" id="height" placeholder="请输入身高" step="0.1">
        </div>
 
        <div class="input-group">
            <label for="weight">体重 (kg)</label>
            <input type="number" id="weight" placeholder="请输入体重" step="0.1">
        </div>
 
        <button>立即计算</button>
 
        <div id="result"></div>
    </div>
 
    <script>
        function calculateBMI() {
            // 获取输入值
            const height = parseFloat(document.getElementById('height').value) / 100;
            const weight = parseFloat(document.getElementById('weight').value);
 
            // 验证输入
            const resultDiv = document.getElementById('result');
            if (!height || !weight || height <= 0 || weight <= 0) {
                resultDiv.className = 'error';
                resultDiv.innerHTML = '&#9888;&#65039; 请输入有效的数值';
                resultDiv.style.display = 'block';
                return;
            }
 
            // 计算 BMI
            const bmi = weight / (height * height);
            const roundedBMI = bmi.toFixed(1);
 
            // 结果分类
            let category = '';
            let className = '';
            if (bmi < 18.5) {
                category = '体重过轻';
                className = 'bmi-normal';
            } else if (bmi < 24) {
                category = '正常范围';
                className = 'bmi-normal';
            } else if (bmi < 28) {
                category = '体重过重';
                className = 'bmi-over';
            } else {
                category = '肥胖';
                className = 'bmi-obese';
            }
 
            // 显示结果
            resultDiv.className = className;
            resultDiv.innerHTML = `
                <strong>BMI 指数:${roundedBMI}</strong><br>
                ${category}(${getAdvice(category)})
            `;
            resultDiv.style.display = 'block';
        }
 
        function getAdvice(category) {
            const advice = {
                '体重过轻': '建议适当增加营养摄入',
                '正常范围': '继续保持健康的生活习惯',
                '体重过重': '建议适当增加运动量',
                '肥胖': '建议咨询专业医生制定健康计划'
            };
            return advice[category];
        }
    </script>
</body>
</html>




发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

blawhickte 发表于 2025-3-19 00:25
其实作为新手, 我还是不建议这么依赖AI工具, 对学习起不到作用
misli8835 发表于 2025-3-19 00:47
SAPLU 发表于 2025-3-19 01:26
COMBHE 发表于 2025-3-19 02:16
谢谢楼主分享
gzfjg 发表于 2025-3-19 06:48
试一下,谢谢分享
sd4869372 发表于 2025-3-19 06:49
谢谢楼主分享
zjtzjt 发表于 2025-3-19 07:15
感谢分享,体重超重了。。。
JackHu114 发表于 2025-3-19 07:44
哈哈哈 不错不错 ,要是能记录变化曲线就好了
laoshizaoan 发表于 2025-3-19 07:51
学习了,感谢
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-3-30 20:32

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表