我有来自slimpicker.js的代码,我用它来获取日历。
我的问题是我需要前几年,比如2012年,2012年,2010年等等。 有人可以告诉我该怎么做吗?
// String building is such fun.
draw: function() {
var str = '<table>';
// Making dropdowns
if (this.options.showMonth || this.options.showYear) {
str += this.addMonthYearDropdowns();
}
str += '<tbody>';
var calendarDate = new Date();
calendarDate.setFullYear(this.calendarYear, this.calendarMonth, 1);
// Leap year
this.options.daysInMonth[1] = (calendarDate.isLeapYear() ? 29 : 28);
// The first day is set as current
var currentDay = (1-(7+calendarDate.getDay()-this.options.startDay)%7);
str += '<tr>';
this.options.dayNames.each( function(name, index) {
str += '<th>' + this.options.dayNames[(this.options.startDay+index)%7].substr(0, this.options.dayChars) + '</th>';
}, this);
str += '</tr>';
// Keeping track of row for hoveredDay purposes
var row = 0;
while (currentDay <= this.options.daysInMonth[this.calendarMonth]){
row += 1;
str += '<tr>';
for (i = 0; i < 7; i++){
if ((currentDay <= this.options.daysInMonth[this.calendarMonth]) && (currentDay > 0)){
str += '<td><a href="#' + this.calendarYear + '|' + (parseInt(this.calendarMonth) + 1) + '|' + currentDay + '" class="' + this.options.dayClass;
// Show the currently selected day
if ( (currentDay == this.currentDay) && (this.calendarMonth == this.currentMonth) && (this.calendarYear == this.currentYear) ) {
str += ' ' + this.options.selectedClass;
this.hoverRow = row;
this.hoverCol = i;
}
// Show today
if ( (currentDay == this.nowDay) && (this.calendarMonth == this.nowMonth) && (this.calendarYear == this.nowYear) ) {
str += ' ' + this.options.todayClass;
}
str += '">' + currentDay + '</a></td>';
} else {
str += '<td class="' + this.options.emptyClass + '"> </td>';
}
currentDay++;
}
str += '</tr>';
}
str += '</tbody></table>';
this.calendar.set('html', str);
this.calendarRows = row;
this.position();
this.addCalendarEvents();
},
addMonthYearDropdowns: function () {
var str = '<thead><tr><th colspan="7">';
if (this.options.showMonth) {
str += '<select tabindex="'+this.tabIndex+'" class="' + this.options.monthClass + '">';
this.options.monthNames.each( function(name, index) {
str += this.addOption(index,name,parseInt(this.calendarMonth));
}, this);
str += '</select>';
}
if (this.options.showYear) {
str += '<select tabindex="'+this.tabIndex+'" class="' + this.options.yearClass + '">';
if (this.options.yearOrder == 'desc'){
for (var y = this.options.yearStart; y > (this.options.yearStart - this.options.yearRange - 1); y--){
str += this.addOption(y,y,parseInt(this.calendarYear));
}
} else {
for (var y = this.options.yearStart; y < (this.options.yearStart + this.options.yearRange + 1); y++){
str += this.addOption(y,y,parseInt(this.calendarYear));
}
}
str += '</select>';
}
str += '</th></tr></thead>';
return str;
},
应该在某处...