修改javascript以显示前几年

时间:2013-01-09 11:29:50

标签: javascript

我有这个javascript代码,我想这应该是代码必须更改的地方。

 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));
                }
            }

日历目前仅显示2013年及以上,我至少需要2012年.. 请在这件事上给予我帮助! 感谢

 dayChars: 1,
        monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
        dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
        daysInMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], // Leap year is added later
        format: 'yyyy/mm/dd',                                          // How the output looks after selection
        yearStart: (new Date().getFullYear()),                     // Default starting year for dropdown options is 5 years ago
        yearRange: 10,                                                 // Show a 10 year span
        yearOrder: 'asc',                                              // Counting up in years
        startDay: 7

4 个答案:

答案 0 :(得分:0)

if (this.options.showYear) {
    str += '<select tabindex="'+this.tabIndex+'" class="' + this.options.yearClass + '">';

    this.options.yearStart -= 1;

或更改options.yearStart到2012而不是2013(当前年度)

答案 1 :(得分:0)

尝试类似:

if(this.options.yearStart >= 2013) {
    this.options.yearStart = 2012;
}

或者

dayChars: 1,
monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
daysInMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], // Leap year is added later
format: 'yyyy/mm/dd',                                          // How the output looks after selection
yearStart: ((new Date().getFullYear()) < 2013 ? (new Date().getFullYear()) : 2012),  // Default starting year for dropdown options is 5 years ago
yearRange: 10,                                                 // Show a 10 year span
yearOrder: 'asc',                                              // Counting up in years
startDay: 7

答案 2 :(得分:0)

更改选项

yearStart: (new Date().getFullYear()),

yearStart: (new Date().getFullYear() - 1), // or any number of years you want to go back

答案 3 :(得分:0)

yearStart: ((new Date().getFullYear()) - 1),