87,924
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Calendar </title>
<style>
.tbody { border-collapse: collapse; border-color: #78B3ED; background-color: #fff; }
#Calendar { width: 212px; height: 150px;}
#CContainer a{ display: block;width: 30px;height: 30px;text-decoration: none; }
#CContainer a:hover { background-color: #B1EAF3;cursor: pointer; }
#LHeader { height: 21px;font-family: "宋体";font-size: 12px; }
.la { background-image:url(iconleft1.jpg);display:block;height: 20px;width: 21px; }
.ra { background-image:url(iconright1.jpg);display:block;height: 20px;width: 21px; }
.now { color: #990000; }
.normal { color: #999; }
#LDay td { font-family:"宋体";font-size: 12px;height: 30px;width: 30px;text-align: center; }
#LBody td { width: 30px;height: 30px;text-align: center;color: #999;font-family:"宋体";font-size: 12px;font-weight: bold; }
#showInfo { width: 212px;height: 30px;font-family:"宋体";font-size: 12px;font-weight: bold;text-align: left; }
</style>
<script type="text/javascript">
/*!
* CalendarSimple
* http://www.cnblogs.com/goodness2010/
*
* Copyright (c) 2009 GoodNess2010
* Date: 2009-1-12 (星期二)
*/
var $ = function(id) { return document.getElementById(id); };
var Calendar = function(cID) {
this.calendar = $(cID);
var D = new Date();
this.year = D.getFullYear();
this.month = D.getMonth() + 1;
this.date = D.getDate();
this.onEnd = function(){};
this.init();
};
Calendar.prototype = {
constructor: Calendar,
init: function() {
var _this = this;
this.drawC( new Date(this.year, this.month, 0).getDate(), new Date(this.year, this.month - 1, 1).getDay(), new Date().getDate());
$('prevM').onclick = function() { _this.prevM(); };
$('nextM').onclick = function() { _this.nextM(); };
$('prevY').onclick = function() { _this.prevY(); };
$('nextY').onclick = function() { _this.nextY(); };
},
getDate: function() {
return new Date(this.year, this.month, 0).getDate();
},
getDay: function() {
return new Date(this.year, this.month - 1, 1).getDay();
},
drawC: function(max, start, now){
var html = '', j = 0, d = new Date(), y = d.getFullYear(), m = d.getMonth() + 1;
html += '<table id="LBody" width="212"><tbody><tr>';
while(j++ < start) {
html += '<td></td>';
}
for(var i = 0 ; i < max; i++) {
if((i + 6 + j) % 7 == 0) html += '<tr>';
html += '<td><a onclick="changeDate(this);" class=' + ((y == this.year && m == this.month && (i + 1) == now) ? 'now' : 'normal') + ' href="#">' + (i + 1) + '</a></td>';
if(!((i + j + 1) * 7) / 7) html += '</tr>';
}
html += '</tbody><table>';
this.calendar.innerHTML = html;
$('showDate').innerHTML = this.year + '.' + this.month;
this.onEnd();
},
prevM: function() {
this.month--;
if(this.month < 1) { this.month = 12;this.year -= 1; }
this.drawC(this.getDate(), this.getDay(), new Date().getDate());
},
nextM: function() {
this.month++;
if(this.month > 12) { this.month = 1;this.year += 1; }
this.drawC(this.getDate(), this.getDay(), new Date().getDate());
},
prevY: function() {
this.year--;
this.drawC(this.getDate(), this.getDay(), new Date().getDate());
},
nextY: function() {
this.year++;
this.drawC(this.getDate(), this.getDay(), new Date().getDate());
}
}
</script>
</head>
<body>
<table id="Calendar" border="1" class="tbody">
<tbody>
<tr>
<td width="142">
<table id="LCalendar" class="tbody" width="212">
<tr>
<td height="21" bgcolor="#78b3ed" width="212">
<table id="LHeader" height="21" width="212">
<tbody>
<tr align="center">
<td align="center" width="21">
<a href="#" class="la" id="prevM"></a>
</td>
<td align="center">
<span id="showDate">2009.11</span>
</td>
<td align="center" width="21">
<a href="#" class="ra" id="nextM"></a>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td height="18">
<table id="LDay" bgcolor="#e7f1fd">
<tbody>
<tr>
<td>日</td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td height="120" width="212" id="CContainer">
</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
<input type="button" value="前一年" id="prevY"/>
<input type="button" value="后一年" id="nextY"/>
<div id="showInfo"></div>
<script type="text/javascript">
var c = new Calendar('CContainer');
c.onEnd = function() {
$('showInfo').innerHTML = "您选择的日期为: " + this.year + '-' + this.month + '-' + this.date;
}
function changeDate(ohref) {
$('showInfo').innerHTML = "您选择的日期为: " + c.year + '-' + c.month + '-' + ohref.innerHTML;
}
</script>
</body>
</html>