-
Notifications
You must be signed in to change notification settings - Fork 0
/
stopwatch.html
38 lines (35 loc) · 1020 Bytes
/
stopwatch.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>스톱워치</title>
<script type="text/javascript">
window.onload = function(){
var startButton = document.getElementById("start");
var stopButton = document.getElementById("stop");
var display = document.getElementById("display");
var startTime, timer;
startButton.onclick = start; //start버튼 활성화
function start(){
startButton.onclick = null;
stopButton.onclick = stop;
startTime = new Date();
//0.1 초마다 경과한 시간 표시
timer = setInterval(function(){
var now = new Date();
display.innerHTML = ((now - startTime)/1000).toFixed(2);
},10);
}
function stop(){
clearInterval(timer);
startButton.onclick = start;
}
};
</script>
</head>
<body>
<p id="display">0.00</p>
<input id="start" type="button" value="start">
<input id="stop" type="button" value="stop">
</body>
</html>