直接上代码。最简单的!第一段是HTML代码和简单的样式。
第二段是JS代码
dateData(3); function dateData(type){ var date = new Date(); date = new Date($('#year').html(), parseInt($('#month').html()),0); var currentMonth = date.getMonth()+1; //当前月 var currentYear = date.getFullYear(); if(type == 0){ if(currentMonth == 0){ currentYear = currentYear - 1; currentMonth = 11; }else{ currentMonth = currentMonth -1; } }else if(type == 1){ if(currentMonth == 11){ currentYear = currentYear + 1; currentMonth = 0; }else{ currentMonth = currentMonth +1; } } date = new Date(currentYear, currentMonth,0); var currentMaxDay = new Date(date.getFullYear(), date.getMonth() + 1,0).getDate(); //当前月 - 最大天 var prevMaxDay = new Date(date.getFullYear(), date.getMonth(),0).getDate(); //上一月 var nextMaxDay = new Date(date.getFullYear(), date.getMonth() + 2,0).getDate(); //下一月 date.setDate(1); var currentWeek = date.getDay(); //当月1日是星期几? if(currentWeek == 0){ currentWeek = 7; } date = new Date(currentYear, currentMonth,0); var html = ""; //遍历上一月 for(var i = prevMaxDay - currentWeek + 1; i <= prevMaxDay;i++){ html+= ""; } //遍历当前月 for(var j = 1;j <= currentMaxDay;j++ ){ html+= ""; } //遍历下一月 for(var j = 1;j <= 42 - currentMaxDay - currentWeek ;j++ ){ html+= ""; } $('#content').html(html); $('#year').html(date.getFullYear()); $('#month').html(date.getMonth() + 1); var width = ($('#TaskCalendar').width() - 2) / 7; $('#TaskCalendar label').css({width:width,float:"left"}); } $(window).resize(function() { var width = ($('#TaskCalendar').width() - 2) / 7; $('#TaskCalendar label').css({width:width,float:"left"}); });
OK!就这么多!