.head { .days { .grey { .links { .today { calendar.js: var daysOfMonth = new Array( var daysOfMonthLY = new Array( var dow = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat', var size = 'width="50" height="30"'; function isLeapYear(num) { function CalendarSelect(Month,Year, offset) { if (window.changeMonth) { } if (window.changeYear) { } if (window.changeDay) { } var output = ''; output += '<form name="Cal">'; return output; function CalendarHead(Month,Year,Select) { output += if (Select) { output += '<td width="50%" align="right">' + for (var month=1; month<=12; month++) { output += '</select>' + for (var year=1900; year<=2100; year++) { output += '</select>'; output += '</td></tr></table>'; return output; function CalendarMonth(M,Y,offset) { firstDay = new Date(Y,M,1); if (startDay < offset) startDay += 7; var days = daysOfMonth; var output = ''; output += for (var i=0; i<7; i++) output += '</tr><tr>'; var column = 0; for (var i=0+offset; i<startDay; i++, column++) for (var i=1; i<=days[M]; i++, column++) { if (column == 6) { if (column > 0) { output += '</tr></table>'; return output; function getAnOptionValue(what) { function CalMonth() { function CalYear() { function CalDay(day,month,year) { var CalendarMonth; current.js: if (!Date.getFullYear) function getMilliseconds() { if (!Date.getMilliseconds) var daysOfWeek = new Array( var monthsOfYear = new Array( function y2k(number) { function dayOfWeek(day,month,year) { function nths(day) { function formatFullDate(day,month,year) { function padout(num) { function formatShortDate(day,month,year) { function formatShortDateUS(day,month,year) { index.htm: <head> <title>Calendar</title> <link rel="stylesheet" href="calendar.css" type="text/css"> <script language="JavaScript" alt=用JavaScript实现的日历 src="current.js"></script> </head> <body bgcolor="#ffffff"> <center> <script language="JavaScript"><!-- function changeDay(day, month, year) { var output = ''; if (window.formatFullDate && window.CalendarSelect) { output += for (var i = 1; i <= 12; i++) { if (i != 12) { output += '</td></tr></table>'; document.write(output); </center> </body> </html> 把这四个文件放在同一目录下。运行index.htm
calendar.css:
.cal {
background-color: #ffffff;
}
color: #bb0000;
font-family: Arial;
font-weight: bold;
text-align: left;
}
color: #0000bb;
font-family: Arial;
font-weight: bold;
text-align: right;
}
color: #ffffff;
font-family: Arial;
font-size: small;
text-align: right;
}
color: #ff0000;
font-family: Arial;
font-size: small;
text-align: right;
}
color: #ffffff;
background-color: #ff0000;
font-family: Arial;
font-size: small;
text-align: right;
}
'January','February','March',
'April','May','June','July',
'August','September','October',
'November','December'
);
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
);
31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
);
'Sun','Mon','Tue','Wed','Thu','Fri');
var border = 'border="1"';
if (((num % 4 == 0) && (num % 100 != 0)) || (num % 400 == 0))
return true;
return false;
}
if (offset == null) offset = 0;
else {
alert('A changeMonth() function has not been defined');
return '';
}
else {
alert('A changeYear() function has not been defined');
return '';
}
else {
alert('A changeDay() function has not been defined');
return '';
}
output += CalendarHead(Month,Year,true);
output += CalendarMonth(Month,Year,offset);
output += '</form>';
}
var output = '';
'<table cellspacing="0" class="cal">' +
'<tr><td align="left" width="100%" class="head">' +
moy[Month-1] + ' ' + Year +
'</td>';
'<select name="Month" onChange="CalMonth()">';
output += '<option value="' + month + '"';
if (month == Month) output += ' selected';
output += '>' + moy[month-1] + '</option>';
}
'<select name="Year" onChange="CalYear();">';
output += '<option value="' + year + '"';
if (year == Year) output += ' selected';
output += '>' + year + '</option>';
}
}
}
M--;
if (offset == null) offset = 0;
startDay = firstDay.getDay();
if (isLeapYear(Y)) days = daysOfMonthLY;
'<table ' + border + ' cellpadding="0" class="cal"><tr>';
output += '<td ' + size + ' class="days">' +
dow[i + offset] + '</td>';
var lastM = M - 1;
if (lastM == -1) lastM = 11;
output += '<td ' + size + ' class="grey">' +
(days[lastM]-startDay+i+1) + '</td>';
var style = ' class="links"';
if (day == i && month == M+1 && year == Y)
style = ' class="today"';
if (window.changeDay)
output += '<td ' + size + '>' +
'<a href="javascript:CalDay('+i+','+(M+1)+','+Y+')"' +
style + '>' + i + '</a></td>';
else
output += '<td ' + size + style + '>' + i + '</td>';
output += '</tr><tr>';
column = -1;
}
}
for (var i=1; column<7; i++, column++)
output += '<td ' + size + ' class="grey">' + i + '</td>';
}
}
return what.options[what.options.selectedIndex].value;
}
CalendarMonth = getAnOptionValue(document.Cal.Month) - 0;
changeMonth(CalendarMonth);
}
CalendarYear = getAnOptionValue(document.Cal.Year) - 0;
changeYear(CalendarYear);
}
CalendarDay = day;
CalendarMonth = month;
CalendarYear = year;
changeDay(CalendarDay,CalendarMonth,CalendarYear);
}
var CalendarYear;
var CalendarDay;
function getFullYear() {
var year = this.getYear();
if (year < 1000) year += 1900;
return year;
}
Date.prototype.getFullYear = getFullYear;
var date = new Date(
this.getFullYear(), this.getMonth(), this.getDate(),
this.getHours(), this.getMinutes(), this.getSeconds(), 0
);
return this.getTime() - date.getTime();
}
Date.prototype.getMilliseconds = getMilliseconds;
'Sunday','Monday','Tuesday','Wednesday',
'Thursday','Friday','Saturday'
);
'January','February','March','April','May','June',
'July','August','September','October','November','December'
);
number = number - 0;
return (number < 1000) ? number + 1900 : number;
}
var a = Math.floor((14 - month)/12);
var y = year - a;
var m = month + 12*a - 2;
var d = (day + y + Math.floor(y/4) - Math.floor(y/100) +
Math.floor(y/400) + Math.floor((31*m)/12)) % 7;
return d;
}
if (day == 1 || day == 21 || day == 31) return 'st';
if (day == 2 || day == 22) return 'nd';
if (day == 3 || day == 23) return 'rd';
return 'th';
}
var dow = dayOfWeek(day,month,year);
return daysOfWeek[dow] + ' ' +
day + nths(day) + ' ' +
monthsOfYear[month-1] +' '+ year;
}
return (num < 10) ? '0' + num : num;
}
return padout(day) + '/' + padout(month) + '/' + year;
}
return padout(month) + '/' + padout(day) + '/' + year;
}
<html>
<script language="JavaScript" alt=用JavaScript实现的日历 src="calendar.js"></script>
size = '';
border = 'border="0"';
dow = new Array('S','M','T','W','T','F','S',
'S','M','T','W','T','F');
moy = new Array(
'Jan','Feb','Mar','Apr','May','Jun',
'Jul','Aug','Sep','Oct','Nov','Dec'
);
alert(new Date(year, month, day));
}
var today = new Date();
var day = today.getDate();
var month = today.getMonth() + 1;
var year = today.getFullYear();
'<table class="cal" border="1"><tr><td valign="top">';
output += '<table><tr><td>' +
CalendarHead(i,year) +
CalendarMonth(i,year,1) +
'</td></tr></table>';
if (i % 3 == 0)
output += '</td></tr><tr><td valign="top">';
else
output += '</td><td valign="top">';
}
}
}
//--></script>