繁体   English   中英

如何修复“ .setFullYear不是函数”

[英]How to fix '.setFullYear is not a function'

我收到错误未捕获的TypeError:尝试修改值时,thisDay.setFullYear不是函数。

我尝试在代码的各个阶段进行调试,并确认我能够从我的moveDate函数中访问thisDay变量,但它不允许我在其上使用任何日期函数。

我一直在与我战斗的代码位于https://jsfiddle.net/ramseys1990/g9cp42bj/3/

主要问题的摘要是:

function moveDate(selection) {

    switch(selection) {
        case "prevYear":
            thisDay.setFullYear((thisDay.getFullYear() - 1).toInteger);
            putCalendar(thisDay.getMonth(), thisDay.getFullYear() - 1);
            break;
        case "prevMonth":
            thisDay.setMonth(thisDay.getMonth() - 1);
            //putCalendar(thisDay.getMonth() - 1, thisDay.getFullYear());
            break;
        case "nextMonth":
            thisDay.setMonth(thisDay.getMonth() + 1);
            //putCalendar(thisDay.getMonth() + 1, thisDay.getFullYear());
            break;
        case "nextYear":
            thisDay.setFullYear(thisDay.getFullYear() + 1);
            //putCalendar(thisDay.getMonth(), thisDay.getFullYear() + 1);
            break;
        case "today":
            thisDay = new Date();
            //putCalendar(thisDay.getMonth(), thisDay.getFullYear());
            break;
    }
    putCalendar(thisDay.getMonth(), thisDay.getFullYear());
    return;
}

我的putCalendar函数是:

function putCalendar(month, year) {


    // Set the date displayed in the calendar 

    thisDay.setMonth = month;
    thisDay.setFullYear = year;
    // Determine the current month
    //var thisMonth = thisDay.getMonth();
    // Determine the current year
    //var thisYear = thisDay.getFullYear();

    // write the calendar to the element with the id 'calendar'
    document.getElementById("demo").innerHTML = createCalendar(thisDay);
}

目前,我的代码文件的顶部是:

"use strict";
var thisDay = new Date();
putCalendar(thisDay.getMonth(), thisDay.getFullYear());

我希望它会将修改后的日期传递给我的putCalendar函数,以重新创建不同年份或月份的日历。

问题是这里

putCalendar(thisDay.getMonth(), thisDay.getFullYear());

调用 getFullYear并将其返回值传递到不是函数的 putCalendar

然后year.setFullYear将获得此值,并且当您尝试调用它时,它将失败。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM