代码示例:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <body>
        <script>
            var year = 1900
            if (year % 4 === 0 && year % 100 !== 0) 
            {                console.log(year + "是普通闰年")            } 
            else if (year % 400 === 0) 
            {                console.log(year + "是世纪闰年")            } 
            else 
            {                console.log(year + "是平年")            }
        </script>        
    </body>
</html>

 

 

 

 代码示例:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <body>
        <script>
            // 一年中的第几天
            var year = 2008
            var mouth = 11
            var day = 8
            // 目标天数
            var today = 0
            // 方法一
            // switch(mouth){
            //     case 12:(today+=30)
            //     case 11:(today+=31)
            //     case 10:(today+=30)
            //     case 9:(today+=31)
            //     case 8:(today+=31)
            //     case 7:(today+=30)
            //     case 6:(today+=31)
            //     case 5:(today+=30)
            //     case 4:(today+=31)                
            //     case 3:
            //     if(year % 4 === 0 && year % 100 !== 0||year % 400 === 0)
            //     {                    
            //         today+=29
            //     }
            //     else
            //     {
            //         today+=28
            //     }
            //     case 2:(today+=31)
            // }
            // console.log(today+=day)
                      // 方法二
            switch (mouth) {
                case 2:
                    (today += 31)
                    break
                case 3:
                    if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
                        today += 60
                    } else {
                        today += 59
                    }
                    break
                case 4:
                    if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
                        today += 91
                    } else {
                        today += 90
                    }
                    break
                case 5:
                    if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
                        today += 121
                    } else {
                        today += 120
                    }
                    break
                case 6:
                    if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
                        today += 152
                    } else {
                        today += 151
                    }
                    break
                case 7:
                    if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
                        today += 182
                    } else {
                        today += 181
                    }
                    break
                case 8:
                    if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
                        today += 213
                    } else {
                        today += 212
                    }
                    break
                case 9:
                    if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
                        today += 244
                    } else {
                        today += 243
                    }
                    break
                case 10:
                    if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
                        today += 274
                    } else {
                        today += 273
                    }
                    break
                case 11:
                    if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
                        today += 305
                    } else {
                        today += 304
                    }
                    break
                case 12:
                    if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
                        today += 335
                    } else {
                        today += 334
                    }
                    break
            }
            console.log(today += day)
        </script>
    </body>
</html>