-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
67 lines (65 loc) · 2.65 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script src="./taiwanDateCalculator.js"></script>
</head>
<body>
<div>
<span>日期: </span
><select id="rule">
<option value="roc" label="民國"></option>
<option value="ad" label="西元"></option>
</select>
<input type="text" id="date" value="1101231" />
<label style="margin-left: 20px" for="convert">民國西元互轉</label>
<input type="checkbox" id="convert" checked disabled />
</div>
<br />
<div>
<span>變數(e.g. : +5, -1, +10...): </span
><input type="text" id="parameter" value="" disabled />
<label style="margin-left: 20px" for="zeroParameter"
>日期純轉換</label
>
<input type="checkbox" id="zeroParameter" checked />
</div>
<br />
<div><span>結果: </span><input type="text" id="dateResult" /></div>
<br />
<input id="calculate" type="button" value="計算" />
<script>
const paramInput = document.getElementById("parameter");
const calBtn = document.getElementById("calculate");
const convertBtn = document.getElementById("convert");
const ruleValue = document.getElementById("rule");
const zeroParameter = document.getElementById("zeroParameter");
calBtn.addEventListener("click", () => {
let date = document.getElementById("date").value;
let param = document.getElementById("parameter").value;
// console.log(ruleValue.value, convertBtn.checked);
document.getElementById("dateResult").value = calculateDate(
date,
param,
ruleValue.value === "roc" ? "0" : "1",
convertBtn.checked ? "1" : "0"
);
});
zeroParameter.addEventListener("click", () => {
if (zeroParameter.checked) {
paramInput.value = "";
paramInput.disabled = true;
convertBtn.disabled = true;
convertBtn.checked = true;
} else {
paramInput.value = "+5";
paramInput.disabled = false;
convertBtn.disabled = false;
convertBtn.checked = false;
}
});
</script>
</body>
</html>