zoukankan      html  css  js  c++  java
  • 关于闰年判断非法测试

    实验要求:根据输入年份判断平年闰年,并识别输入中是否有非法字符

    闰年:

    1、普通年份能被4整除且不能被100整除的为闰年;

    2、整百的年份能被400整除的是闰年。

    实验截图

    源代码:

    <!DOCTYPE html>
    <html>
    <head lang="en">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="page-enter" content="revealtrans(duration=3,transition=0)"/>
    <meta http-equiv="windows-target" content="_top">
    </head>
    
    <body bgcolor="FFCC00" text="#FFFFFF" background="background2.jpg" bgproperties="fixed" leftmargin="50"><center><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
    请输入年份:<input type="text" id="input" autofocus="autofocus"/>
    <input type="submit" value="确定" onclick="test()"/>
    <p id="output"></p>
    
    <script>
    function test(){
        if(!checkNum(document.getElementById("input").value)||document.getElementById("input").value==0)
            document.getElementById("output").innerHTML="ERROR";
        else if((document.getElementById("input").value%4==0&&document.getElementById("input").value%100!=0)||document.getElementById("input").value%400==0)
            document.getElementById("output").innerHTML="the year is 闰年 ";
        else
            document.getElementById("output").innerHTML="the year is 平年";
    }
    function checkNum(value) {
        var Reg = /^[0-9]*$/;
        if (Reg.test(value)) return true;
        return false;
    }
    </script>
    </center>
    </body>
    </html>
  • 相关阅读:
    C#将数据库导出成Excel,再从Excel导入到数据库中。
    C#连接SQL server2008数据库
    Spring session共享问题 将session放入redis(转)
    nginx服务(转)
    数据库索引知识点(转)
    快速打开电脑计算器
    js的json使用
    支付宝的帮你投 长时间看收益
    axure 获取团队项目svn 修改帐号
    育儿书单-樊登读书会
  • 原文地址:https://www.cnblogs.com/hanven72/p/4398388.html
Copyright © 2011-2022 走看看