カレンダー
カレンダー
<html>
<head>
<script type="text/javascript" language="javascript" >
//今日の日付情報を取得
var today = new Date();
today_year = today.getYear();
if(today_year < 2000) today_year += 1900;
today_month = today.getMonth() + 1;
today_day = today.getDate();
var date = new Date();
function dispCalendar(intMonth)
{
html="";
date.setDate(1);
if(intMonth == 1)
{
date.setMonth(date.getMonth() - 1);
}
else if(intMonth == 2)
{
date.setMonth(date.getMonth() + 1);
}
year = date.getYear();
if(year < 2000) year += 1900;
month = date.getMonth() + 1;
//各月の末日を準備
days = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
//うるう年の判定
if((year % 4 == 0) && (year % 100 != 0) || (( year % 400) == 0))
{
days[1] = 29;//4年に一度
}
//色を指定
color_holiday = "pink"; //休日
color_saturday = "skyblue"; //土曜日
color_normal = "black"; //平日
color_today = "yellow"; //今日を選択した色
html+="<table>";
html+="<tr>";
html+="<td colspan=2>";
html+="<input type=button id=prev name=prev value='前月' onClick='dispCalendar(1);' />";
html+="</td>";
html+="<td colspan=3>";
html+= year + "年" + month + "月";
html+="</td>";
html+="<td colspan=2>";
html+="<input type=button id=next name=next value='次月' onClick='dispCalendar(2);' />";
html+="</td>";
html+="</tr>";
html+="<tr>";
html+="<td>日</td>";
html+="<td>月</td>";
html+="<td>火</td>";
html+="<td>水</td>";
html+="<td>木</td>";
html+="<td>金</td>";
html+="<td>土</td>";
html+="</tr>";
flg=0;
//1日から最大31日までの日にちを作成します
for(i = 1-date.getDay();i<=31;i+=7)
{
//1週間の日にち(7個分)ずつ作成する
html+="<tr align=center>";
for(j=i;j<i+7;j++)
{
if((j>0) && (j<=days[month - 1]))
{
date.setDate(j);
week = date.getDay();
if(today_day == j && year == today_year && month == today_month)
{
html += "<td bgcolor='" + color_today + "'>";
}
else
{
html += "<td>";
}
flg = 0;
if(week == 0)
{
//flgの値は0のまま
}
else if(week == 6)
{
flg = 1;
}
else
{
flg = 2;
}
switch(flg)
{
case 0:
html += "<font color='" + color_holiday + "'>" + j + "</font></td>";
break;
case 1:
html += "<font color='" + color_saturday + "'>" + j + "</font></td>";
break;
case 2:
html += "<font color='" + color_normal + "'>" + j + "</font></td>";
break;
}
}
else
{
html += "<td></td>";
}
}
html+="</tr>";
}
html+="</table>";
document.getElementById("result").innerHTML = html;
}
</script>
</head>
<body onLoad="dispCalendar(0);">
<form name=frm1 id=frm1 method="POST">
<label style="background-color:darkblue;color:white;text-align:center;width:90px;">カレンダー</label>
<div id=result />
<br />
<br />
</form>
</body>
</html>
|
|