-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.html
51 lines (49 loc) · 1.31 KB
/
demo.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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>倒计时</title>
</head>
<body>
<input type="text" id="hours" placeholder="00" />时
<input type="text" id="minutes" placeholder="00"/>分
<input type="text" id="seconds" placeholder="00"/>秒
<input type="button" value="开始倒计时" onclick="testf()">
</body>
</html>
<script>
//设定倒计时时间
function testf(){
var hours = Number(document.getElementById("hours").value);
var minutes = Number(document.getElementById("minutes").value);
var seconds = Number(document.getElementById("seconds").value);
var start;
start = setInterval(function(){
//逻辑
// if (seconds==0&&minutes==0&&hours==0){
// alert("计时结束");
// clearInterval(start);
// }
seconds--;
if(seconds == -1){
minutes--;
if(minutes == -1){
hours--;
if(hours == -1){
minutes--;
clearInterval(start);
return;
}
minutes = 59;
}
seconds = 59;
}
// if (seconds==0&&minutes==0&&hours==0){
// alert("计时结束");
// }
document.getElementById("seconds").value = seconds<10?"0"+seconds:seconds;
document.getElementById("minutes").value = minutes<10?"0"+minutes:minutes;
document.getElementById("hours").value = hours<10?"0"+hours:hours;
},1000);
}
</script>