zoukankan      html  css  js  c++  java
  • 计算星期几

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
        </head>
        <body>
            <tr>
                <td>请输入年:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                <td><input type="text" id="year" value=""/></td>
            </tr>
            <br>
            <tr>
                <td>请输入月:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                <td><input type="text" id="month" value=""/></td>
            </tr>
            <br>
            <tr>
                <td>请输入日:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                <td><input type="text" id="date" value=""/></td>
            </tr>
            <br>
            <tr>
                <td>请输出星期几:</td>
                <td><input type="text" id="day"/></td>
            </tr>
            <br>
            <tr>
                <td><input type="button" value="计算" id="btn"/></td>
                <td><input type="button" value="清空" id="res"/></td>
            </tr>
        </body>
    </html>
    <script>
        var oYear = document.getElementById( "year" );
        var oMonth = document.getElementById( "month" );
        var oDate = document.getElementById( "date" );
        var oBtn = document.getElementById( "btn" );
        var oDay = document.getElementById( "day" );
        var oRes = document.getElementById( "res" );
        oBtn.onclick = function(){
    var m = parseInt( oMonth.value );
    var y = parseInt( oYear.value );
    var d = parseInt( oDate.value );
     
            var sum = 0;
             switch( m ){
                    case 12 : sum += 30;//11月
                    case 11 : sum += 31;
                    case 10 : sum += 30;
                    case 9 : sum += 31;
                    case 8 : sum += 31;
                    case 7 : sum += 30;
                    case 6 : sum += 31;
                    case 5 : sum += 30;
            
                    case 4 : sum += 31; //3月
                    case 3 : {
                        y%4==0&&y%100!=0||y%400==0 ? sum += 29 : sum += 28;
                    }
                    case 2 : sum += 31; // 1月
                    case 1 : sum += d;
                }
            
             if( sum%7 == 0 ){
                oDay.value = "星期天"
             }else if( sum%7 == 1 ){
                oDay.value = "星期一"
             }else if( sum%7 == 2 ){
                oDay.value = "星期二"
             }else if( sum%7 == 3 ){
                oDay.value = "星期三"
             }else if( sum%7 == 4 ){
                oDay.value = "星期四"
             }else if( sum%7 == 5 ){
                oDay.value = "星期五"
             }else if( sum%7 == 6 ){
                oDay.value = "星期六"
             }
            
        }
        oRes.onclick = function(){
            oYear.value="";
            oMonth.value="";
            oDate.value="";
            oDay.value="";
        
        }
        
    </script>
    <!-- alert( sum );-->
  • 相关阅读:
    Windows异常处理机制介绍
    OD 与 Win7
    对VC6编译优化的简单测试
    QQ版本号(2012/07/22 更新)
    OD与调试符号
    Balsamiq Mockups
    hotpatch热修补
    QQ
    VC的编译开关参数大全
    隐藏秘技:vc输出类的layout信息
  • 原文地址:https://www.cnblogs.com/tis100204/p/10328818.html
Copyright © 2011-2022 走看看