本文实例为大家分享了jQuery实现日历效果的具体代码,供大家参考,具体内容如下
jquery是用的是2.0版本。
1、html代码
显示详细签到详情 * { margin: 0px; padding: 0px; font-size: 14px; font-family: '微软雅黑' } .signincalendar { } .signincalendar table { margin: 0 auto; border-radius: 0.5em; border: 1px solid #00D3D3; box-shadow: 0px 0px 7.5px 5px #00D3D3; } .signincalendar table tr { } .signincalendar table tr td { width: 50px; height: 34px; text-align: center; border: 1px solid black; border-radius: 0.5em; font-weight: bolder; } .signincalendar table tr.firsttr td, .signincalendar table tr.secondtr td { border: 0px; } table tr.secondtr td:nth-child(1) { color: #E13838; border-radius: 0px -1px 1px #FFFF68; } table tr.secondtr td:nth-child(2) { color: orange; border-radius:0px -1px 1px #FFFF68; } table tr.secondtr td:nth-child(3) { color: #C2C200; border-radius:0px -1px 1px #FFFF68; } table tr.secondtr td:nth-child(4) { color: green; border-radius:0px -1px 1px #FFFF68; } table tr.secondtr td:nth-child(5) { color: #00D3D3; border-radius:0px -1px 1px #FFFF68; } table tr.secondtr td:nth-child(6) { color: blue; border-radius:0px -1px 1px #FFFF68; } table tr.secondtr td:nth-child(7) { color: purple; border-radius: 0px -1px 1px #FFFF68; } table tr td.cantsign { background: none repeat scroll 0% 0% #9B9B9B; color: #F2F2F2; } table tr.threetr td { background: #9AFAA0; }
2、以下是mycanledar.js的代码
// Javascript document
var nstr = new Date(); // 获取当前日期
var changedYear = nstr.getFullYear(); // 年份
var changedMonth = nstr.getMonth(); // 月份
var dnow = nstr.getDate(); // 今日日期
var n1str = new Date(changedYear, changedMonth, 1); // 当月第一天Date
var initfirstday = n1str.getDay(); // 当月第一天星期几
var daynumber = getMonthAllDay(changedMonth, changedYear);
showCanledar(changedMonth, initfirstday, dnow, daynumber);
reloadyear();
reloadmonth(1);
function reloadyear() {
var initYearSelect = $("#currentyear option");
initYearSelect.each(function() {
if ($(this).val().substring(0, 4) == changedYear) {
$(this).attr("selected", true);
}
});
}
function reloadmonth(isinit) {
var initMonthSelect = $("#currentmonth option");
initMonthSelect.each(function() {
if (isinit == 1) {
if ($(this).index() == changedMonth) {
$(this).attr("selected",true);
}
} else {
if ($(this).index() == changedMonth - 1) {
$(this).attr("selected", true);
}
}
});
}
// 是否为闰年
function is_leap(year) {
return (year % 100 == 0 ? res = (year % 400 == 0 ? 1 : 0)
: res = (year % 4 == 0 ? 1 : 0));
}
// 获得下拉列表的年
function getNewYear() {
// alert("得到年");
return $("#currentyear option:selected").text().substring(0, 4);
}
// 获得下拉列表的月
function getNewMonth() {
// alert("得到月");
return $("#currentmonth option:selected").text();
}
// 获取当月的天数
function getMonthAllDay(month, year) {
var m_days = new Array(31, 28 + is_leap(year), 31, 30, 31, 30, 31, 31, 30,
31, 30, 31);
return m_days[month];
}
// 获得某年某月某日是星期几
function getFirstWeekDay(year, month, day) {
var date = new Date();
date.setFullYear(year);
date.setMonth(month);
date.setDate(day);
return date.getDay();
}
// 获得表格行数
function requiredRows(allday, firstday) {
var trstr = Math.ceil((allday + firstday) / 7);
// alert("trstr"+trstr);
return trstr;
}
function showCanledar(month, firstday, dnow, allday) {
var rows = requiredRows(allday, firstday);
var tb = "| "; tb += ""; tb += ""; tb += " | ||||||
| 日 | 一 | 二 | 三 | 四 | 五 | 六 | "; tb += "
| " : tb += " | " +date_str + " | "; // 过滤无效日期(小于等于零的、大于月总天数的) // 打印日期:今天底色为红 // 查询月签到情况 } tb += "|||||
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。



