<!DOCTYPE html>
<html>
<head>
<title>標準体重計算機</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
font-family: Arial, sans-serif;
background-color: #f6f6f6;
margin: 0;
padding: 0;
box-sizing: border-box;
}
h1 {
text-align: center;
margin-top: 50px;
font-size: 36px;
color: #666;
}
form {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 50px;
}
label {
font-size: 24px;
color: #333;
}
input[type="text"] {
font-size: 24px;
padding: 10px;
border: none;
border-radius: 5px;
margin-top: 10px;
text-align: center;
background-color: #f9f9f9;
color: #333;
}
button {
font-size: 24px;
padding: 10px 20px;
border: none;
border-radius: 5px;
margin-top: 20px;
background-color: #4CAF50;
color: white;
cursor: pointer;
}
.result {
text-align: center;
margin-top: 50px;
font-size: 36px;
color: #666;
}
</style>
</head>
<body>
<h1>標準体重計算機</h1>
<form id="form">
<label for="height">身長(cm)を入力してください:</label>
<input type="text" id="height" name="height" placeholder="170">
<button type="submit">計算する</button>
</form>
<div class="result" id="result"></div>
<script>
// フォーム送信時の処理
document.getElementById("form").addEventListener("submit", function(event) {
event.preventDefault(); // デフォルトのフォーム送信をキャンセルする
var height = parseInt(document.getElementById("height").value); // 身長を取得する
if (!isNaN(height)) { // 身長が数値である場合
var standardWeight = (height - 100) * 0.9; // 標準体重を計算する
document.getElementById("result").innerHTML = "あなたの標準体重は " + Math.round(standardWeight * 10) / 10 + " kgです。"; // 結果を表示する
} else { // 身長が数値でない場合
document.getElementById("result").innerHTML = "身長を正しい形式で入力してください。"; // エラーメッセージを表示する
}
});
</script>
</body>
</html>
【ジョーク】
標準体重って何が基準か分からなくて困りますよね。でも、世の中には標準体重の基準を超える人もいるそうです。彼らが言うには、その分だけ愛情も増えるとか…。