hyeonga_code

Ajax_innerHTML_1 초마다 현재 시간을 출력합니다. 본문

Ajax

Ajax_innerHTML_1 초마다 현재 시간을 출력합니다.

hyeonga 2023. 10. 17. 07:59
반응형


- webapp > ch02 > 'clock.html' 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>시계</title>
<script type="text/javascript">
 
    // 시간을 호출하는 함수를 작성합니다.
    function printTime() {
    
        var clock = document.getElementById("clock");
        
        // 현재 시간을 가져옵니다.
        var now = new Date();
        
        // clock이라는 이름을 가진 태그에 출력할 내용의 형식을 지정합니다.
        clock.innerHTML = now.getFullYear() + "년 " 
                            + (now.getMonth() + 1+ "월 " 
                            + now.getDate() + "일 " 
                            + now.getHours() + "시 "
                            + now.getMinutes() + "분 " 
                            + now.getSeconds() + "초";
        
        setTimeout("printTime()"1000);
    }
    
    // 화면이 로드되면 자동으로 함수를 실행합니다.
    window.onload = function() {
        printTime();
    }
</script>
</head>
<body>
    현재 시간은
    <span id="clock">
        <!-- 출력될 내용의 위치입니다. -->
    </span> 입니다.
</body>
</html>














반응형