我正在编写此脚本以显示我的日历,错误控制台显示“未定义日历”。我无法弄清楚它有什么问题。
这是 John WHS 要求的 .js 页面的代码
function calendar()
{
var calDate = new Date("July 6, 2015");
document.write("<table id = 'calendar_table'>");
writeCalTitle(calDate);
writeDayNames();
writeCalDays(calDate);
document.write("</table>");
}
//function for the title of the calendar
//the parameter is a date object
function writeCalTitle(calendarDay)
{
// This is an array for the months
var monthName = ["January","February","March","April","May","June","July","August"
,"September","October","November","December"]
var thisMonth = calendarDay.getMonth();
var thisYear = caalendarDay.getFullYear();
document.write("<tr>");
document.write("<th id='calendar_head' colspan='7'>");
document.write(monthName[month] + " " +year);
document.write("</th>");
document.write("</tr>");
}
function writeDayNames()
{
var dayName = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
document.write("<tr>");
// This is a for loop
for(var i = 0; i<dayName.length; i++)
{
document.write("<th id='calendar_weekdays'>" + dayName[i]+"</th>");
}
document.write("</tr>");
}
function daysInMonth(calendarDay)
{
var dayCount = [31,28,31,30,31,30,31,31,30,31,30,31];
var thisYear = calendarDay.getFullYear();
var thisMonth = calendarDay.getMonth();
if (thisYear % 4 == 0)
{
if ((thisYear % 100 != 0 || (thisYear % 400 ==0 ))
{
dayCount[1] = 29;
}
}
return dayCount[thisMonth];
}
function writeCalDays(calendarDay)
{
// says the starting day of the month
var day = new Date(calendarDay.getFullYear(), calendarDay.getMonth(), 1 );
var weekDay = day.getDay();
// writes blank cells before the starting day
document.write("<tr>");
for (var i = 0; i < weekDay; i++)
{
document.write("<td></td>");
}
// writes cells for the days of the month
var totalDays = dayIn Month(calendarDay);
for (var i = 1; i<= totalDays; i++)
{
day.setDate(i);
weekDay = day.getDay();
}
if (weekDay == 0) document.write("<tr>");
document.write("<td class='calendar_dates'>" + i + "</td>");
if (i == highlightDay)
{
document.write("<td class='calendar_dates' id='calendar_today'>" + i + "</td>");
}
else
{
document.write("<td class='calendar_dates'>" + i + "</td>");
}
if (weekDay == 6) document.write("</tr>");
}