zoukankan      html  css  js  c++  java
  • 课后作业-雇员注册表单

    作业题目:

    作业代码:

    <html>
    <form action="" method="post">
    雇员编号<input type="text" id="id1" name="number" size=4><br>
    雇员姓名<input type="text" id="id2" name="username" size=4><br>
    雇员工作<input type="text" id="id3" name="job" size=4><br>
    雇员日期<input type="text" id="id4" name="date" size=4><br>
    基本工资<input type="text" id="id5" name="page" size=4><br>
    奖金<input type="text" id="id6" name="uppage" size=4><br>
    <input type="submit" value="提交" id="id7" onclick="checkform()" />
    <script type="text/javascript">
    function checkform(){
            
        if(document.getElementById('id1').value.length==0)
        {alert('编号为空');
        document.getElementById('id1').focus();
        return false;}
        var value = document.getElementById("id1").value;
        var reg=/^[1-9]d*$|^0$/;   
        if(reg.test(value)!=true)
        {alert('编号不是数字');
        document.getElementById('id1').focus();
        return false;}
    
        if(document.getElementById('id2').value.length==0)
        {alert('姓名为空');
        document.getElementById('id2').focus();
        return false;}
    
        if(document.getElementById('id3').value.length==0)
        {alert('工作为空');
        document.getElementById('id3').focus();
        return false;}
    
        if(!document.getElementById("id4").value.match("^[0-9]{4,4}/[0-9]{2,2}/[0-9]{2,2}$")) 
        {alert( "日期格式错误 xxxx/xx/xx");
        document.getElementById('id4').focus();
        return false;}
    
        if(!document.getElementById("id5").value.match("^[0-9]{1,9}.[0-9]{2,2}$"))
        {alert( "工资格式错误x...x.xx ");
        document.getElementById('id5').focus();
        return false;}
        
        if(!document.getElementById("id6").value.match("^[0-9]{1,9}.[0-9]{2,2}$"))
        {alert( "奖金格式错误x...x.xx ");
        document.getElementById('id6').focus();
        return false;}
    }
    </script>
    </form>
    <body>
    </body>
    </html>

    运行截图:

            

                

    学会的东西:

    正则表达式 ^……$开始和结束的标志;[0-9]表示0~9,{0,1}0或1,{0,9}0或1或2或……或9,当然也可以{4,4}就代表有4个;[]{}算一对,每队之间也可以加格式,比如我们要判断xxxx-xx-xx/xxxx-xx-x日期就可以写:^[0-9]{4,4}-[0-9]{2,2}-[0-9]{1,2}$,然后直接判断就行,正则表达式如果不符合返回false符合会返回true,所以大胆用if判断就好。

    感悟:

    《请回答1988》除了阿泽到中国比赛时剧中反映对中国的敌视之外还是很好看的,无止境的走亲戚但也很好吃,不想><开学。。。

  • 相关阅读:
    20110603 本日跌的股票之后一段时间轻易不要碰
    一日三省
    火电排污新标准年内出台 撬动千亿脱硝市场
    20082011大股东增持专题
    收评:5月24日资金流向(摘自益盟)
    2011年中期业绩预增前20家公司
    2011大股东十大增持概念股全景图
    放不下期货
    从众是通向地狱最廉价的门票
    在ASP.NET中获取Get方式和Post方式提交的数据
  • 原文地址:https://www.cnblogs.com/Amyheartxy/p/6360599.html
Copyright © 2011-2022 走看看