[Javascript] - 달력(심플)

Javascript 2011. 6. 28. 18:46
반응형

[Javascript] - 달력(심플)

<html>

<head>

<script language="JavaScript">

function showCalendar(y, m) {

    var text = '<table>\n<tr><td colspan=7 style="text-align:center">';

    text += '<span onclick="showCalendar('+(y-1)+','+m+')"> Y- </span>';

    text += '<span onclick="showCalendar('+(m==1?(y-1)+','+12:y+','+(m-1))+')"> M- </span>';

    text += '[' + y + '/' + ((m < 10) ? ('0' + m) : m) + ']';

    text += '<span onclick="showCalendar('+(m==12?(y+1)+','+1:y+','+(m+1))+')"> M+ </span>';

    text += '<span onclick="showCalendar('+(y+1)+','+m+')"> Y+ </span>';

    text += '</td>';

    var d1 = (y+(y-y%4)/4-(y-y%100)/100+(y-y%400)/400

          +m*2+(m*5-m*5%9)/9-(m<3?y%4||y%100==0&&y%400?2:3:4))%7;

    for (i = 0; i < 42; i++) {

        if (i%7==0) text += '</tr>\n<tr>';

        if (i < d1 || i >= d1+(m*9-m*9%8)/8%2+(m==2?y%4||y%100==0&&y%400?28:29:30))

            text += '<td> </td>';

        else

            text += '<td' + (i%7 ? '' : ' style="color:red;"') + '>' + (i+1-d1) + '</td>';

    }

    document.getElementById('calendarDiv').innerHTML = text + '</tr>\n</table>';

}

</script>

</head>

<body onload="showCalendar(2006,8)">

</body>

</html>

 

<script language="JavaScript">

function showCalendar(y, m) {

    var text = '<table bgcolor="white" border="0">\n<tr><td colspan=7 style="text-align:center">';

    text += '<span onclick="showCalendar('+(y-1)+','+m+')" style="cursor:pointer;"> 작년 </span>';

    text += '<span onclick="showCalendar('+(m==1?(y-1)+','+12:y+','+(m-1))+')" style="cursor:pointer;"> 이전달 </span>';

    text += '[' + y + '/' + ((m < 10) ? ('0' + m) : m) + ']';

    text += '<span onclick="showCalendar('+(m==12?(y+1)+','+1:y+','+(m+1))+')" style="cursor:pointer;"> 다음달 </span>';

    text += '<span onclick="showCalendar('+(y+1)+','+m+')" style="cursor:pointer;"> 내년 </span>';

    text += '</td>';

    text += '<td>';

    text += '<font color="blue">닫기</font>';

    text += '</td>';

    var d1 = (y+(y-y%4)/4-(y-y%100)/100+(y-y%400)/400

          +m*2+(m*5-m*5%9)/9-(m<3?y%4||y%100==0&&y%400?2:3:4))%7;

    for (i = 0; i < 42; i++) {

        if (i%7==0) text += '</tr>\n<tr>';

        if (i < d1 || i >= d1+(m*9-m*9%8)/8%2+(m==2?y%4||y%100==0&&y%400?28:29:30))

            text += '<td> </td>';

        else

            text += '<td' + (i%7 ? '' : ' style="color:red;"') + '>' + (i+1-d1) + '</td>';

    }

    document.getElementById('calendarDiv').innerHTML = text + '</tr>\n</table>';

}

function opencal() {

 document.getElementById("calendarDiv").style.display="block";

}

function closecal() {

 document.getElementById("calendarDiv").style.display="none";

}

</script>

<body onload="showCalendar(<%=TYear%>,<%=TMonth%>)">

달력


반응형
: