以下函数为啥调用不了。

function getDays(y, m, d) { //当前日期在本年过了多少天
    var sum=0;
    switch(m-1) {
    case 11:
        sum+=30;
    case 10:
        sum+=31;
    case 9:
        sum+=30;
    case 8:
        sum+=31;
    case 7:
        sum+=31;
    case 6:
        sum+=30;
    case 5:
        sum+=31;
    case 4:
        sum+=30;
    case 3:
        sum+=31;
    case 2:
        if(y%4==0&&y%100!=0||y%400==0) {
            sum+=29;
        } else {
            sum+=28;
        };
    case 1:
        sum+=30;
    }
    sum=sum+d;
    return sum;
}
function otherDays(y,m,d) {//判断日期在这一年还剩多少天
    var otherDays;
    if(y%4==0&&y%100!=0||y%400==0) {
        otherDays=366-getDays(y,m,d);
    } else {
        otherDays=365-getDays(y,m,d);
    };
    return otherDays;
}
function countDays(y1,m1,d1,y2, m2,d2) {
    var days;
    var sum=0;
    if(y1==y2) {
        days=getDays(y1,m1,d1)-getDays(y2,m2,d2)
             days>=0?days:-days;
    } else if(y1<y2) {
        for(i=y1+1; i<y2; i++) {
            if(i%4==0&&i%100!=0||i%400==0) {
                sum+=366;
            } else {
                sum+=365
            };
        }
        days=sum+ otherDays(y1,m1,d1)+getDays(y2,m2, d2)
    } else {
        for(i=y2+1; i<y1; i++) {
            if(i%4==0&&i%100!=0||i%400==0) {
                sum+=366;
            } else {
                sum+=365
            };
        }
        days=sum+ getDays(y1,m1,d1)+otherDays(y2,m2, d2);
    }
    return days;
}
alert(countDays(1998,6,27,2017, 6,2));


qq_如風_1
浏览 1706回答 2
2回答

qq_如風_1

getDays1(y1, m1, d1);getDays2(y2, m2, d2);otherDays1(y1,m1,d1);otherDays2(y2,m2,d2)countDays(y1,m1,d1,y2, m2,d2),做过这样的修改,使参数匹配后仍是不行

李晓健

这么长的代码,没兴趣看,不过一般 switch case 后面应该有break的吧,没见你写
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript