作为程序员,没有合适的工具,就得手搓一个,PC端,移动端均可适用。废话不多说,直接上代码。
HTML:
<div class="calculator"><div class="input-group"><label for="weight">体重 (kg):</label> <input id="weight" type="number" placeholder="请输入您的体重 (kg)"></div><div class="input-group"><label for="speed">跑步速度:</label><select id="speed"><option value="7.0">慢跑(8 km/h,7.0 MET)</option><option value="9.8">中速跑(10 km/h,9.8 MET)</option><option value="11.5">快跑(12 km/h,11.5 MET)</option></select></div><div class="input-group"><label for="duration">跑步时长 (分钟):</label> <input id="duration" type="number" placeholder="请输入跑步时间 (分钟)"></div><button onclick="calculateRunningCalories()">计算卡路里消耗</button><div id="result" class="result"></div></div>
JS:
function calculateRunningCalories() {
const weight = parseFloat(document.getElementById("weight").value);
const speedMET = parseFloat(document.getElementById("speed").value);
const duration = parseFloat(document.getElementById("duration").value);
const resultDiv = document.getElementById("result");
if (isNaN(weight) || isNaN(speedMET) || isNaN(duration) || weight <= 0 || duration <= 0) {
resultDiv.textContent = "请输入有效的所有数值!";
return;
}
// 计算卡路里消耗
const caloriesBurned = weight * speedMET * (duration / 60);
// 显示结果
resultDiv.textContent = `卡路里消耗:约 ${caloriesBurned.toFixed(2)} 大卡`;
}
CSS:
.calculator {
width: 100%;
background-color: #333;
color: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}
label {
display: block;
margin-bottom: 10px;
font-size: 16px;
}
input, select {
width: 100%!important;
padding: 10px!important;
margin-bottom: 20px;
color: #000000;
border-radius: 5px;
border: 1px solid #555;
font-size: 16px!important;
background-color: #ffffff!important;
}
button {
width: 100%;
padding: 10px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: orange;
}
.result {
font-size: 18px;
margin-top: 20px;
text-align: center;
}
option {
background-color: #ffffff;
}
p {
font-size: 18px;
margin-top: 5px!important;
}
标签:color,卡路里,important,跑步,background,计算器,font,border,size
From: https://blog.csdn.net/yuchangchenTT/article/details/144200383