只是个简单的日历模板,各位可根据需要自行添加需要的功能。该模板更多的是提供了关于年、月、日、月初、月末、星期的获取函数。各位可根据需要自行获取。欢迎提供更简便的方式方法,互相学习提高!谢谢~~
一 | 二 | 三 | 四 | 五 | 六 |
---|---|---|---|---|---|
<script type="text/javascript">
window.onload = function() {
/**
/**
/**
var tdNodes = document.getElementsByTagName("td");
var selectYearNode = document.getElementById("selectYear");
var selectMonthNode = document.getElementById("selectMonth");
var prevYearNode = document.getElementById("prevYear");
var prevMonthNode = document.getElementById("prevMonth");
var nextMonthNode = document.getElementById("nextMonth");
var nextYearNode = document.getElementById("nextYear");
var now = new Date();
var ary = now.toArray();
function changeYearOrMonth(iYearDiff,iMonthDiff) {
var currentYear = parseInt(selectYearNode.innerHTML);
var currentMonth = parseInt(selectMonthNode.innerHTML);
var newDate = new Date(currentYear+iYearDiff,currentMonth+iMonthDiff-1,1);
var dateAry = newDate.toArray();
insertAllMonth(dateAry[0],dateAry[1]);
};
function insertAllMonth(iYear,iMonth) {
selectYearNode.innerHTML = iYear;
selectMonthNode.innerHTML = iMonth;
var firstDay = getFirstDay(iYear,parseInt(iMonth)-1);
var maxDay = getMaxDayOfMonth(iYear,iMonth);
var prevMonthMaxDay = getMaxDayOfMonth(iYear,parseInt(iMonth)-1);
var i = 0;
for(i=firstDay;i>0;i--) {
tdNodes[i-1].innerHTML = prevMonthMaxDay--;
tdNodes[i-1].className = "";
}
for(i=1+firstDay;i<=maxDay+firstDay;i++) {
tdNodes[i-1].innerHTML = i-firstDay;
if(iYear == ary[0] && iMonth == ary[1] && i-firstDay == ary[2]) {
tdNodes[i-1].className = "currentMonth currentDay";
}else if(i%7 < 2){
tdNodes[i-1].className = "currentMonth week";
}else {
tdNodes[i-1].className = "currentMonth";
}
}
var one = 1;
for(;i<=tdNodes.length;i++) {
tdNodes[i-1].innerHTML = one++;
tdNodes[i-1].className = "";
}
};
insertAllMonth(ary[0],ary[1]);
prevYearNode.onclick = function() {
changeYearOrMonth(-1,0);
};
prevMonthNode.onclick = function() {
changeYearOrMonth(0,-1);
};
nextMonthNode.onclick = function() {
changeYearOrMonth(0,1);
};
nextYearNode.onclick = function() {
changeYearOrMonth(1,0);
};
};