-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path倒计时.html
More file actions
88 lines (78 loc) · 2.45 KB
/
Copy path倒计时.html
File metadata and controls
88 lines (78 loc) · 2.45 KB
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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>倒计时工具</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
font-family: Arial, sans-serif;
}
h1 {
text-align: center;
margin-bottom: 20px;
}
form {
text-align: center;
margin-bottom: 20px;
}
label {
font-size: 18px;
margin-right: 10px;
}
#minutes {
width: 150px;
padding: 5px;
font-size: 16px;
}
button {
padding: 10px 20px;
font-size: 16px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
#countdown {
font-size: 64px;
text-align: center;
margin-top: 40px;
}
</style>
</head>
<body>
<form>
<label for="minutes">倒计时时间(分钟):</label>
<input type="number" id="minutes" name="minutes" placeholder="输入倒计时时间(分钟)" required>
<br>
<button type="button" onclick="startCountdown()">开始倒计时</button>
</form>
<div id="countdown"></div>
<script>
function startCountdown() {
var minutes = parseInt(document.getElementById("minutes").value);
if (isNaN(minutes) || minutes <= 0) {
alert("请输入有效的倒计时时间(分钟)!");
return;
}
var count = minutes * 60;
var countdownElem = document.getElementById("countdown");
var updateCountdown = setInterval(function() {
var minutesLeft = Math.floor(count / 60);
var secondsLeft = count % 60;
countdownElem.innerHTML = minutesLeft + " 分钟 " + secondsLeft + " 秒";
count--;
if (count < 0) {
clearInterval(updateCountdown);
countdownElem.innerHTML = "时间到!";
}
}, 1000);
}
</script>
</body>
</html>