用htML网页 语言代码解决以下问题 仅输入一个班级的应到与实到,遵守以下条件, 1 若请假人数小于等于班级总人数的20%不需要扣分 2 若请假的人数超出班级总人数的20%但没有超出班级总人数的50%则超出20% 请假的每个人扣0.5分, 3 如果请假人数超出50%的超出50%的每个请假人数扣1分。 4 已上条件中的总人数的20%和50%和30%如果不为整数则先进行四舍五入再计算 求应扣多少分。
时间: 2024-02-05 14:11:29 浏览: 12
以下是一个简单的 HTML 网页代码,可以解决这个问题:
```html
<!DOCTYPE html>
<html>
<head>
<title>请假扣分计算器</title>
</head>
<body>
<h1>请假扣分计算器</h1>
<form>
<label for="total">班级总人数:</label>
<input type="number" id="total" name="total" required><br><br>
<label for="actual">实到人数:</label>
<input type="number" id="actual" name="actual" required><br><br>
<label for="absent">请假人数:</label>
<input type="number" id="absent" name="absent" required><br><br>
<button type="button" onclick="calculate()">计算</button><br><br>
<label for="score">应扣分数:</label>
<input type="number" id="score" name="score" readonly><br><br>
</form>
<script>
function calculate() {
var total = parseInt(document.getElementById("total").value);
var actual = parseInt(document.getElementById("actual").value);
var absent = parseInt(document.getElementById("absent").value);
var threshold20 = Math.round(total * 0.2); // 20% 的阈值
var threshold50 = Math.round(total * 0.5); // 50% 的阈值
var score = 0; // 应扣分数
if (absent <= threshold20) {
score = 0;
} else if (absent <= threshold50) {
score = Math.round((absent - threshold20) * 0.5 * 10) / 10;
} else {
score = Math.round((threshold50 - threshold20) * 0.5 * 10) / 10
+ Math.round((absent - threshold50) * 1 * 10) / 10;
}
document.getElementById("score").value = score;
}
</script>
</body>
</html>
```
这个网页包含一个表单,需要输入班级总人数、实到人数和请假人数。当用户点击“计算”按钮时,会执行 JavaScript 函数 `calculate()`,该函数会根据输入的信息计算出应扣多少分,然后将结果显示在一个只读的文本框中。在 JavaScript 中,我们使用了 `Math.round()` 函数对阈值进行四舍五入,以确保它们是整数。