<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"> <title>Insert title here</title> <script type="text/javascript"> window.onload = function() { document.getElementById("showCal").addEventListener("click", process, false); document.getElementById("etc").style.display = "none"; var pYear = document.getElementById("pYear"); pYear.onclick = Yearminus; var pMonth = document.getElementById("pMonth"); pMonth.onclick = Monthminus; var nMonth = document.getElementById("nMonth"); nMonth.onclick = Monthplus; var nYear = document.getElementById("nYear"); nYear.onclick = Yearplus;
} var str = ""; var now = new Date(); var year = now.getFullYear(); //2013 var month = now.getMonth(); var day = now.getDate(); //4 function process() {
//alert(year+"/"+(month+1)+"/"+day);
//해당 달의 1일이 무슨 요일이냐? var firstDay = new Date(year, month, 1); var yoil = firstDay.getDay(); //요일 얻기. 0~6(일~토) //alert(yoil);
//해당 달의 날 수 얻기 var nalsu = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); if ((year % 4 === 0) && (year % 100 !== 0) || (year % 400 === 0)) { nalsu[1] = 29; //윤년 체크 } makeData(yoil, nalsu[month], year, month + 1, day); document.getElementById("disp").innerHTML = str;
function makeData(yoil, nalsu, year, month, day) { //alert(yoil+" "+nalsu+" "+year+" "+month+" "+day); str = ""; //출력 결과를 위한 문자열 더하기 str += "<table width='70%' align='center' border='1'>"; str += "<tr style='font-size:20px'><tr><th colspan='7'>" + year + "년" + month + "월</th></tr>"; str += "<tr style=background-color:#abcdef>"; var weekTitle = new Array("일", "월", "화", "수", "목", "금", "토"); for ( var a = 0; a < weekTitle.length; a++) { str += "<th>" + weekTitle[a] + "</th>"; }
str += "</tr>"; //날 수 채우기 var no = 1; var currentCell = 0; var ju = Math.ceil((nalsu + yoil) / 7); //몇주인지가 나옴. //alert(month + "월은" + ju + "주"); for ( var row = 1; row <= ju; row++) { str += "<tr>"; //이 아래 7바퀴를 돌림 for ( var col = 1; col <= 7; col++) { if (no > nalsu) break; //1부터 날수 까지만 숫자 채우기
if (currentCell < yoil) { str += "<td> </td>"; currentCell++; } else { if (no === day) { str += "<td id='today' style='color:red'><b>" + no + "</b></td>"; } else { str += "<td>" + no + "</td>"; } no++; } } str += "</tr>";
}
str += "</table>"; } function Yearminus() { year--; process(); } function Monthminus() { if (month == 0) { year--; month = 11; }else{ month--; } process(); } function Yearplus() { year++; process(); } function Monthplus() { if (month > 10) { year++; month = 0; }else{ month++; } process(); }