(function($) { function calendarWidget(el, params) { var now = new Date(); var thismonth = now.getMonth(); var thisyear = now.getYear() + 1900; var today = now.getDate(); var opts = { month: thismonth, year: thisyear, today:today }; $.extend(opts, params); var monthNames = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']; var dayNames = ['日', '一', '二', '三', '四', '五', '六']; month = i = parseInt(opts.month); year = parseInt(opts.year); today = parseInt(opts.today); var m = 0; var table = ''; // next month if (month == 11) { var next_month = '' + monthNames[0] + ' ' + (year + 1) + ''; } else { var next_month = '' + monthNames[month + 1] + ' ' + (year) + ''; } // previous month if (month == 0) { var prev_month = '' + monthNames[11] + ' ' + (year - 1) + ''; } else { var prev_month = '' + monthNames[month - 1] + ' ' + (year) + ''; } table += ('

'+monthNames[month]+' '+year+'

'); // uncomment the following lines if you'd like to display calendar month based on 'month' and 'view' paramaters from the URL //table += (''); //table += (''); table += (''); table += ''; for (d=0; d<7; d++) { table += ''; } table += ''; var days = getDaysInMonth(month,year); var firstDayDate=new Date(year,month,1); var firstDay=firstDayDate.getDay(); var prev_days = getDaysInMonth(month,year); var firstDayDate=new Date(year,month,1); var firstDay=firstDayDate.getDay(); var prev_m = month == 0 ? 11 : month-1; var prev_y = prev_m == 11 ? year - 1 : year; var prev_days = getDaysInMonth(prev_m, prev_y); firstDay = (firstDay == 0 && firstDayDate) ? 7 : firstDay; var i = 0; for (j=0;j<42;j++){ if ((j'+ (prev_days-firstDay+j+1) +''); } else if ((j>=firstDay+getDaysInMonth(month,year))) { i = i+1; table += (''); }else{ // console.log(opts.signDays); // console.log($.inArray((j-firstDay+1),opts.signDays)) if($.inArray((j-firstDay+1),opts.signDays)!=-1){ //特定days table += (''); }else if(today==(j-firstDay+1) && month==thismonth){ //今天 table += (''); }else{ table += (''); } } if (j%7==6) table += (''); } table += ('
' + dayNames[d] + '
'+ i +''+(j-firstDay+1)+''+(j-firstDay+1)+''+(j-firstDay+1)+'
'); el.html(table); } function getDaysInMonth(month,year) { var daysInMonth=[31,28,31,30,31,30,31,31,30,31,30,31]; if ((month==1)&&(year%4==0)&&((year%100!=0)||(year%400==0))){ return 29; }else{ return daysInMonth[month]; } } // jQuery plugin initialisation $.fn.calendarWidget = function(params) { calendarWidget(this, params); return this; }; })(jQuery);