본문 바로가기
Web Programming/HTML CSS JAVASCRIPT

[JavaScript] 달력 만들기

달력 만들기







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
89
90
91
92
93
94
95
96
97
98
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
td {
 width: 60px;
 height: 60px;
 text-align: center;
 font-size: 20px;
 font-family: 바탕;
 border:2px dotted #AC58FA;
 border-radius:8px;
}
 
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
 
 
<title>Calender</title>
 
<script language="javascript" type="text/javascript">
var today = new Date(); // 오늘 날짜//지신의 컴퓨터를 기준으로
//today 에 Date객체를 넣어줌 //ex)5일  
function prevCalendar() {
 
 
 today = new Date(today.getFullYear(), today.getMonth() - 1, today.getDate());
 buildCalendar(); // 현재 달 
}
 
function nextCalendar() {
 
 
 today = new Date(today.getFullYear(), today.getMonth() + 1, today.getDate());
 buildCalendar();
}
 
function buildCalendar() {// 현재 달fur
 var nMonth = new Date(today.getFullYear(), today.getMonth(), 1);  // 이번 달의 첫째 날
 var lastDate = new Date(today.getFullYear(), today.getMonth()+10); // 이번 달의 마지막 날
 var tblCalendar = document.getElementById("calendar");     // 테이블 달력을 만들 테이블
 var tblCalendarYM = document.getElementById("calendarYM");    // yyyy년 m월 출력할 곳
 tblCalendarYM.innerHTML = today.getFullYear() + "년 " + (today.getMonth() + 1+ "월";  // yyyy년 m월 출력
// 기존 테이블에 뿌려진 줄, 칸 삭제
 
 
 while (tblCalendar.rows.length > 2) {
  tblCalendar.deleteRow(tblCalendar.rows.length - 1);
 }
 var row = null;
 row = tblCalendar.insertRow();
 var cnt = 0;
// 1일이 시작되는 칸을 맞추어 줌
 for (i=0; i<nMonth.getDay(); i++) {
  cell = row.insertCell();
  cnt = cnt + 1;
 }
 
 for (i=1; i<=lastDate.getDate(); i++) { 
  cell = row.insertCell();
  cell.innerHTML = i;
  cnt = cnt + 1;
  if (cnt%7 == 0)// 1주일이 7일 이므로
   row = calendar.insertRow();// 줄 추가
 }
 
}
 
</script>
 
</head>
<body>
<table id="calendar" boarder="3" align="center">
 <tr>
     <td><label onclick="prevCalendar()"><</label></td>
        <td colspan="5" align="center" id="calendarYM">yyyy년 m월</td>
        <td><label onclick="nextCalendar()">>
           
        </label></td>
    </tr>
    <tr>
     <td align="center"></td>
     <td align="center"></td>
     <td align="center"></td>
     <td align="center"></td>
     <td align="center"></td>
     <td align="center"></td>
     <td align="center"></td>
   </tr>
 
 
</table>
<script language="javascript" type="text/javascript">
buildCalendar();
</script>
</body>
</html>
 
cs


'Web Programming > HTML CSS JAVASCRIPT' 카테고리의 다른 글

[CSS] 부모 자식 선택자  (0) 2018.05.09
[CSS] 선택자  (0) 2018.05.09
[JavaScript] 계산기  (0) 2018.04.15
[JavaScript] 이미지 자동 변경  (0) 2018.04.15
[JavaScript] 대화상자와 함수  (0) 2018.04.08