#calendar
{...}
{ width:140px; border:solid 1px #b8f0e7; height:100px; position:absolute; display:none;}
#calendar table {...} { margin:0px; background-color: #b8f0e7; font-size:12px;}
#calendar input {...} { border:none 0px #ffffff; height:16px;}
#cBar td {...} { background-color:#fff;}
#cDay td {...} { padding-top:2px; background-color:#ffffff;}
#cBar a:link,a:visited,a:active {...} { color: #000000; text-decoration: none; font-size:12px;}
#cBar a:hover {...} { text-decoration: none; color: #FF0000; font-size:12px;}
a.cDayS:link,a.cDayS:visited,a.cDayS:active {...} { color: #FF0000; text-decoration: none; font-size:12px;}
a.cDayS:hover {...} { text-decoration: none; color: #FF0000; font-size:12px;}
a.cDay:link,a.cDay:visited,a.cDay:active {...} { color: #000000; text-decoration: none; font-size:12px;}
a.cDay:hover {...} { text-decoration: none; color: #000000; font-size:12px;}
#calendar table {...} { margin:0px; background-color: #b8f0e7; font-size:12px;}
#calendar input {...} { border:none 0px #ffffff; height:16px;}
#cBar td {...} { background-color:#fff;}
#cDay td {...} { padding-top:2px; background-color:#ffffff;}
#cBar a:link,a:visited,a:active {...} { color: #000000; text-decoration: none; font-size:12px;}
#cBar a:hover {...} { text-decoration: none; color: #FF0000; font-size:12px;}
a.cDayS:link,a.cDayS:visited,a.cDayS:active {...} { color: #FF0000; text-decoration: none; font-size:12px;}
a.cDayS:hover {...} { text-decoration: none; color: #FF0000; font-size:12px;}
a.cDay:link,a.cDay:visited,a.cDay:active {...} { color: #000000; text-decoration: none; font-size:12px;}
a.cDay:hover {...} { text-decoration: none; color: #000000; font-size:12px;}
function
setCalendar()
...
{
this.aWeek = ['一','二','三','四','五','六'];
this.aDay = new Array(); this.oDate = new Date();
this.toYear = this.oDate.getYear();
this.toMonth = this.oDate.getMonth() + 1;
this.toDay = this.oDate.getDate();
if(this.toYear<1900) this.toYear+= 1900;
this.setThisDate = function(d) ...{
if(d!='') ...{
var aDate = d.split('-');
this.oDate = new Date(aDate[0], aDate[1] - 1, aDate[2]);
this.thisYear = this.oDate.getYear();
this.thisMonth = this.oDate.getMonth() + 1; this.thisDay = this.oDate.getDate();
if(this.thisYear<1900) this.thisYear+= 1900;
}
else ...{
this.thisYear = this.toYear;
this.thisMonth = this.toMonth;
this.thisDay = this.toDay;
}
}
this.writeCalendar = function() ...{
var html = '<table width="140" border="0" cellspacing="0" cellpadding="0"><tr><td id="cBar">';
html+= '<table width="140" border="0" cellspacing="0" cellpadding="0"><tr>';
html+= '<td><a href="javascript:oCalendar.setGoYear('-')" title="上一年"><</a><input type="text" id="calendarYear" maxlength="4" style="width:30px; height:16px;" οnkeyup="oCalendar.checkYear()"><a href="javascript:oCalendar.setGoYear('+')" title="下一年">></a><a href="javascript:oCalendar.setGoDay()">今天</a><a href="javascript:oCalendar.setGoMonth('-')" title="上一月"><</a><input type="text" id="calendarMonth" maxlength="2" style="width:18px; height:16px;" οnkeyup="oCalendar.checkMonth()"><a href="javascript:oCalendar.setGoMonth('+')" title="下一月">></a></td><td><a href="javascript:oCalendar.closeC('+')" title="关闭">×</a></td>';
html+= '</tr></table></td></tr>';
html+= '<tr><td id="cDay"></td></tr></table>';
html+= '<iframe src="javascript:false" style="border:0px; position:absolute; visibility:inherit; top:0px; left:0px; width:150px; height:200px; z-index:-1; filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';"></iframe>';
document.getElementById('calendar').innerHTML = html;
}
this.writeCDay = function() ...{
this.checkDate();
this.getDays(document.getElementById('calendarYear').value,
document.getElementById('calendarMonth').value);
var html = '<table id="XList" width="100%" border="0" cellspacing="1" cellpadding="0"><tr style="">';
html+= '<td align="center" style="color:red; background-color:#d8f1f6;">日</td>';
for(var i=0; i<this.aWeek.length; i++) html+= '<td align="center" style="background-color:#d8f1f6;">' + this.aWeek[i] + '</td>'; html+= '</tr>';
for(var i=0; i<6; i++) ...{
var x = i*7;
if(i==0||this.aDay[x]!='')...{
html+= '<tr>';
html+= this.getTDay(this.aDay[x], 1);
for(var j=1; j<7; j++) ...{
var x = 7*i+j;
html+= this.getTDay(this.aDay[x], 0);
}
html+= '</tr>';
}
}
html+= '</table>';
document.getElementById('cDay').innerHTML = html;
}
this.getTDay = function(d, t) ...{
var style = '';
var aStyle = 'cDay';
if(t==1) ...{
style+= 'color:red;';
aStyle = 'cDayS';
}
if(this.isToDate==1 && d==this.toDay) style+= 'font-weight:bold;';
if(this.isThisDate==1 && d==this.thisDay) style+= 'background-color:#cccccc;';
return '<td align="center" style="' + style + '"><a href="javascript:oCalendar.selectDate(' + d + ')" class="' + aStyle + '">' + d + '</a></td>';
}
this.getDays = function(y, m) ...{
for(var i=0; i<42; i++) this.aDay[i] = '';
var days = new Date(y, m, 0).getDate();
var week = new Date(y, m-1, 1).getDay();
for(var i=0; i<days; i++) this.aDay[i+week] = i + 1;
}
this.setGoYear = function(x) ...{
switch (x) ...{
case '+': document.getElementById('calendarYear').value = document.getElementById('calendarYear').value * 1 + 1; break;
case '-': document.getElementById('calendarYear').value-= 1; break;
default: document.getElementById('calendarYear').value = this.thisYear;
}
this.writeCDay();
}
this.setGoMonth = function(x) ...{
var m = document.getElementById('calendarMonth').value;
switch (x) ...{
case '+': m = m * 1 + 1; break;
case '-': m-= 1; break;
default: m = this.thisMonth;
}
if(m<1) ...{
m=12;
document.getElementById('calendarYear').value-= 1;
}
else if(m>12) ...{
m=1; document.getElementById('calendarYear').value = document.getElementById('calendarYear').value * 1 + 1;
}
document.getElementById('calendarMonth').value = m;
this.writeCDay();
}
this.setGoDay = function() ...{
document.getElementById('calendarYear').value = this.toYear;
document.getElementById('calendarMonth').value = this.toMonth;
this.writeCDay();
}
this.getThisDate = function() ...{
alert(this.thisYear+'年'+this.thisMonth+'月'+this.thisDay+'日');
}
this.checkDate = function() ...{
if(document.getElementById('calendarYear').value==this.toYear && document.getElementById('calendarMonth').value==this.toMonth) this.isToDate = 1;
else this.isToDate = 0;
if(document.getElementById('calendarYear').value==this.thisYear && document.getElementById('calendarMonth').value==this.thisMonth) this.isThisDate = 1;
else this.isThisDate = 0;
}
this.selectDate = function(d) ...{
document.getElementById(this.id).value = document.getElementById('calendarYear').value + '-' + document.getElementById('calendarMonth').value + '-' + d;
this.closeC();
}
this.showC = function(id, e) ...{
this.id = id;
this.setThisDate(document.getElementById(this.id).value);
this.writeCDay(); this.setGoYear('');
this.setGoMonth('');
document.getElementById('calendar').style.display = 'block';
var cX = e.clientX; var cY = e.clientY;
var sX = document.body.clientWidth;
var sY = document.body.clientHeight;
if(cX>70) cX-= 70; if((sX-cX)<80) cX = sC - 80; if((sY-cY)<150) cY = sY - 150;
document.getElementById('calendar').style.left = cX +'px';
document.getElementById('calendar').style.top = cY + document.body.scrollTop + 'px';
}
this.closeC = function() ...{
document.getElementById('calendar').style.display = 'none';
}
this.checkYear = function() ...{
var y = document.getElementById('calendarYear').value; if(y>1900&&y<3000) this.writeCDay();
}
this.checkMonth = function() ...{
var y = document.getElementById('calendarMonth').value; if(y>0&&y<13) this.writeCDay();
}
this.writeCalendar();
}
this.aWeek = ['一','二','三','四','五','六'];
this.aDay = new Array(); this.oDate = new Date();
this.toYear = this.oDate.getYear();
this.toMonth = this.oDate.getMonth() + 1;
this.toDay = this.oDate.getDate();
if(this.toYear<1900) this.toYear+= 1900;
this.setThisDate = function(d) ...{
if(d!='') ...{
var aDate = d.split('-');
this.oDate = new Date(aDate[0], aDate[1] - 1, aDate[2]);
this.thisYear = this.oDate.getYear();
this.thisMonth = this.oDate.getMonth() + 1; this.thisDay = this.oDate.getDate();
if(this.thisYear<1900) this.thisYear+= 1900;
}
else ...{
this.thisYear = this.toYear;
this.thisMonth = this.toMonth;
this.thisDay = this.toDay;
}
}
this.writeCalendar = function() ...{
var html = '<table width="140" border="0" cellspacing="0" cellpadding="0"><tr><td id="cBar">';
html+= '<table width="140" border="0" cellspacing="0" cellpadding="0"><tr>';
html+= '<td><a href="javascript:oCalendar.setGoYear('-')" title="上一年"><</a><input type="text" id="calendarYear" maxlength="4" style="width:30px; height:16px;" οnkeyup="oCalendar.checkYear()"><a href="javascript:oCalendar.setGoYear('+')" title="下一年">></a><a href="javascript:oCalendar.setGoDay()">今天</a><a href="javascript:oCalendar.setGoMonth('-')" title="上一月"><</a><input type="text" id="calendarMonth" maxlength="2" style="width:18px; height:16px;" οnkeyup="oCalendar.checkMonth()"><a href="javascript:oCalendar.setGoMonth('+')" title="下一月">></a></td><td><a href="javascript:oCalendar.closeC('+')" title="关闭">×</a></td>';
html+= '</tr></table></td></tr>';
html+= '<tr><td id="cDay"></td></tr></table>';
html+= '<iframe src="javascript:false" style="border:0px; position:absolute; visibility:inherit; top:0px; left:0px; width:150px; height:200px; z-index:-1; filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';"></iframe>';
document.getElementById('calendar').innerHTML = html;
}
this.writeCDay = function() ...{
this.checkDate();
this.getDays(document.getElementById('calendarYear').value,
document.getElementById('calendarMonth').value);
var html = '<table id="XList" width="100%" border="0" cellspacing="1" cellpadding="0"><tr style="">';
html+= '<td align="center" style="color:red; background-color:#d8f1f6;">日</td>';
for(var i=0; i<this.aWeek.length; i++) html+= '<td align="center" style="background-color:#d8f1f6;">' + this.aWeek[i] + '</td>'; html+= '</tr>';
for(var i=0; i<6; i++) ...{
var x = i*7;
if(i==0||this.aDay[x]!='')...{
html+= '<tr>';
html+= this.getTDay(this.aDay[x], 1);
for(var j=1; j<7; j++) ...{
var x = 7*i+j;
html+= this.getTDay(this.aDay[x], 0);
}
html+= '</tr>';
}
}
html+= '</table>';
document.getElementById('cDay').innerHTML = html;
}
this.getTDay = function(d, t) ...{
var style = '';
var aStyle = 'cDay';
if(t==1) ...{
style+= 'color:red;';
aStyle = 'cDayS';
}
if(this.isToDate==1 && d==this.toDay) style+= 'font-weight:bold;';
if(this.isThisDate==1 && d==this.thisDay) style+= 'background-color:#cccccc;';
return '<td align="center" style="' + style + '"><a href="javascript:oCalendar.selectDate(' + d + ')" class="' + aStyle + '">' + d + '</a></td>';
}
this.getDays = function(y, m) ...{
for(var i=0; i<42; i++) this.aDay[i] = '';
var days = new Date(y, m, 0).getDate();
var week = new Date(y, m-1, 1).getDay();
for(var i=0; i<days; i++) this.aDay[i+week] = i + 1;
}
this.setGoYear = function(x) ...{
switch (x) ...{
case '+': document.getElementById('calendarYear').value = document.getElementById('calendarYear').value * 1 + 1; break;
case '-': document.getElementById('calendarYear').value-= 1; break;
default: document.getElementById('calendarYear').value = this.thisYear;
}
this.writeCDay();
}
this.setGoMonth = function(x) ...{
var m = document.getElementById('calendarMonth').value;
switch (x) ...{
case '+': m = m * 1 + 1; break;
case '-': m-= 1; break;
default: m = this.thisMonth;
}
if(m<1) ...{
m=12;
document.getElementById('calendarYear').value-= 1;
}
else if(m>12) ...{
m=1; document.getElementById('calendarYear').value = document.getElementById('calendarYear').value * 1 + 1;
}
document.getElementById('calendarMonth').value = m;
this.writeCDay();
}
this.setGoDay = function() ...{
document.getElementById('calendarYear').value = this.toYear;
document.getElementById('calendarMonth').value = this.toMonth;
this.writeCDay();
}
this.getThisDate = function() ...{
alert(this.thisYear+'年'+this.thisMonth+'月'+this.thisDay+'日');
}
this.checkDate = function() ...{
if(document.getElementById('calendarYear').value==this.toYear && document.getElementById('calendarMonth').value==this.toMonth) this.isToDate = 1;
else this.isToDate = 0;
if(document.getElementById('calendarYear').value==this.thisYear && document.getElementById('calendarMonth').value==this.thisMonth) this.isThisDate = 1;
else this.isThisDate = 0;
}
this.selectDate = function(d) ...{
document.getElementById(this.id).value = document.getElementById('calendarYear').value + '-' + document.getElementById('calendarMonth').value + '-' + d;
this.closeC();
}
this.showC = function(id, e) ...{
this.id = id;
this.setThisDate(document.getElementById(this.id).value);
this.writeCDay(); this.setGoYear('');
this.setGoMonth('');
document.getElementById('calendar').style.display = 'block';
var cX = e.clientX; var cY = e.clientY;
var sX = document.body.clientWidth;
var sY = document.body.clientHeight;
if(cX>70) cX-= 70; if((sX-cX)<80) cX = sC - 80; if((sY-cY)<150) cY = sY - 150;
document.getElementById('calendar').style.left = cX +'px';
document.getElementById('calendar').style.top = cY + document.body.scrollTop + 'px';
}
this.closeC = function() ...{
document.getElementById('calendar').style.display = 'none';
}
this.checkYear = function() ...{
var y = document.getElementById('calendarYear').value; if(y>1900&&y<3000) this.writeCDay();
}
this.checkMonth = function() ...{
var y = document.getElementById('calendarMonth').value; if(y>0&&y<13) this.writeCDay();
}
this.writeCalendar();
}