-
Notifications
You must be signed in to change notification settings - Fork 0
/
dzz.html
132 lines (116 loc) · 3.88 KB
/
dzz.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<title>电阻测量计算器</title>
<style>
body {
font-family: "Microsoft YaHei", sans-serif;
background-color: #f5f5f5;
}
h1 {
text-align: center;
margin-top: 50px;
}
form {
margin: 50px auto;
max-width: 600px;
padding: 20px;
border: 1px solid #ccc;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 0 10px #ccc;
}
label {
display: block;
margin-bottom: 10px;
font-size: 16px;
}
input[type="number"] {
width: 100%;
padding: 10px;
border-radius: 5px;
border: 1px solid #ccc;
font-size: 16px;
box-sizing: border-box;
}
input[type="button"] {
display: block;
margin: 20px auto;
padding: 10px 20px;
background-color: #4CAF50;
color: #fff;
border: none;
border-radius: 5px;
font-size: 18px;
cursor: pointer;
box-shadow: 0 0 10px #4CAF50;
}
input[type="button"]:hover {
background-color: #3e8e41;
box-shadow: 0 0 10px #3e8e41;
}
#result {
text-align: center;
margin-top: 50px;
font-size: 24px;
}
#result p {
margin-bottom: 10px;
}
#result .success {
color: #4CAF50;
}
#result .fail {
color: #f44336;
}
</style>
</head>
<body>
<h1>电阻测量计算器</h1>
<form>
<label for="a1">第一相位的电阻值(欧姆):</label>
<input type="number" id="a1" required>
<label for="a2">第二相位的电阻值(欧姆):</label>
<input type="number" id="a2" required>
<label for="a3">第三相位的电阻值(欧姆):</label>
<input type="number" id="a3" required>
<input type="button" value="计算" onclick="calculate()">
</form>
<div id="result"></div>
<script>
function calculate() {
var a1 = parseFloat(document.getElementById("a1").value);
var a2 = parseFloat(document.getElementById("a2").value);
var a3 = parseFloat(document.getElementById("a3").value);
var a0 = (a1 + a2 + a3) / 3;
var b = a1 - a0;
var c = (b / a0) / 0.01;
var result = document.getElementById("result");
result.innerHTML = "";
var header = document.createElement("h2");
header.innerText = "计算结果";
result.appendChild(header);
if (isNaN(a0) || isNaN(b) || isNaN(c)) {
var error = document.createElement("p");
error.innerText = "输入值不能为空或非数字,请重新输入!";
result.appendChild(error);
} else {
var value = document.createElement("p");
value.innerHTML = "电阻值为:" + a0.toFixed(5) + "欧姆";
result.appendChild(value);
var deviation = document.createElement("p");
deviation.innerHTML = "相对误差为:" + c.toFixed(5) + "%";
result.appendChild(deviation);
var status = document.createElement("p");
if (c <= 2) {
status.innerHTML = "<span class='success'>测量结果合格</span>";
} else {
status.innerHTML = "<span class='fail'>测量结果不合格</span>";
}
result.appendChild(status);
}
}
</script>
</body>
</html>