본문 바로가기

Study/Programming

자바스크립트 달력

반응형

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script language="javascript">
function clickcal(){
    var year = document.cal.year.options[document.cal.year.selectedIndex].value;
    var month = document.cal.month.options[document.cal.month.selectedIndex].value;
    var day = 1;
    var date = new Date(parseInt(year), parseInt(month), day)
   
    var lastDay = new Date(parseInt(year), parseInt(month), 0).getDate();

    document.write(date.getFullYear() +"년 "
            +(date.getMonth()) +"월 "
            +(date.getDay()) +"요일 " +"<br>");
   
   
    for(var i=1; i<=lastDay; i++){
   
        if(i%7==0){
            document.write((i) +" " +"<br>");   
        }else{
            document.write((i)+" ");
        }
   }
}
</script>
</head>
<body>
<form name="cal">
    <select name="year" onclick="clickcal()">
        <option value="2008">2008년</option>
        <option value="2009">2009년</option>
    </select>  
    <select name="month" onclick="clickcal()">
        <option value="1">1월</option>
        <option value="2">2월</option>
        <option value="3">3월</option>
        <option value="4">4월</option>
        <option value="5">5월</option>
    </select>
<!--
    <input type="button" value="Click" onclick="clickcal()">
    <br><br>
    <textarea name="output" cols="20" rows="10" readonly></textarea>
-->
</form>
</body>
</html>

반응형

'Study > Programming' 카테고리의 다른 글

자바 예외처리  (0) 2009.05.18
자바스크립트 ID 저장, 중복체크  (0) 2009.05.16
자바 Array  (0) 2009.05.15
자바 String, StringBuffer  (0) 2009.05.15
자바 equals  (0) 2009.05.15