カレンダー

いつのカレンダーかを指定し「カレンダー作成]ボタンをクリック


今月  来月  前月  次ぎのBoxで指定 年/

<SCRIPT language="JavaScript"><!--
lastDay = new Array("31","28","31","30","31","30","31","31","30","31","30","31");
function Calendar(){
nowDate = new Date(); //現在の日付を取得
nowYear = nowDate.getFullYear(); //現在の年数を4桁で取得
nowMonth = nowDate.getMonth()+1; //現在が何月か
nowDay = nowDate.getDate(); //現在の日付(1-31)を取得
if(document.form1.what[1].checked){ //来月
nowMonth = nowDate.getMonth()+1 +1; //現在が何月か nowDay = 0;
if(nowMonth==13){
nowYear = nowYear + 1;
nowMonth = 1;
}
}
if(document.form1.what[2].checked){ //前月
nowMonth = nowDate.getMonth()+1-1; //現在が何月か nowDay = 0;
if(nowMonth==0){
nowYear = nowYear - 1;
nowMonth = 12;
}
}
if(document.form1.what[3].checked){ //入力指定の年月
if(document.form1.nenn.value=="" || document.form1.tuki.value==""){
alert("年月を入力してください!");
}else{
nowYear = document.form1.nenn.value;
nowMonth = document.form1.tuki.value; nowDay = 0;
}
}
//うるう年の調整(4で割り切れ、100で割り切れない年はうるう年。または400で割り切れたらうるう年
if(((nowYear%4==0)&&(nowYear%100!=0))||(nowYear%400==0))lastDay[1] = 29;
startDay = new Date(nowYear,nowMonth-1,1); //今月の1日の日付オブジェクトを生成
startYoubi = startDay.getDay(); //今月の1日が何曜日かを求める
count = 0; //日数をカウントしていく変数(7で行送りするため)

str = "<table border>";
str += "<tr><th colspan=7>"+nowYear+"年"+nowMonth+"月のカレンダー</th></tr>";//タイトル
str += "<tr bgcolor=green align='center'><th bgcolor=pink><font color=red>日</font></th> <th>月</th><th>火</th><th>水</th><th>木</th><th>金</th><th>土</th></tr>"; //曜日の表示
str += "<tr align='center'>";
for(i=0;i<startYoubi;i++){
str += "<td></td>"; //1日になるまで空のセルを作成(曜日を埋めていく)
count++;
}
for(i=1;i<=lastDay[nowMonth-1];i++){ //1日から月末まで繰り返す
if(count==0)str += "<td bgcolor=pink>"; //日曜日はピンク色で
else str += "<td>";
if(i==nowDay){ //今日の日付の場合,赤色・強調で表示
str += "<font color='red'><b>" + i + "</b></font></td>";
}else{
str += i + "</td>";
}
count++;
if(count==7){
str += "</tr><tr align='center'>"; //7列まで達すると次の行に
count = 0;
}
}
str += "</tr></table>";

newW = window.open('','win','width=400,height=300,left=300,top=100');
newW.document.write(str);
newW.document.close();
}
//--></SCRIPT>
</head>
<body>
<form name="form1">
<input type="radio" name="what" value="now" checked>今月 
<input type="radio" name="what" value="next">来月 
<input type="radio" name="what" value="forward">前月 
<input type="radio" name="what" value="intxt">次ぎのBoxで指定
<input type="text" name="nenn" size="4">年/
<input type="text" name="tuki" size="2">月<br>
<input type="button" name="bt" value="カレンダー作成" onclick="Calendar();">
</form>

end(01/7/7)