• 前台校验


    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
        </head>
        <body>
            <form name="frm" method="post">
                <table>
                    <tr><td>用户名:</td><td><input type="text" name="" id="usernameId" value="" /></td><td><span id="userSpanId"></span></td></tr>
                    <tr><td>密码:</td><td><input type="password" name="" id="pwdId" value="" /></td><td><span id="pwdSpanId"></span></td></tr>
                    <tr><td>确认密码:</td><td><input type="password" name="" id="confPwdId" value="" /></td><td><span id="confPwdSpanId"></span></td></tr>
                    <tr><td><input type="button" onclick="check()" value="注册" /></td></tr>
                </table>
            </form>
            
            <script type="text/javascript">
                function check(){
                    var result1=checkUserName();
                    var result2=checkPwd();
                    var result3=checkTwoPwd();
                    
                    if(result1 && result2 && result3){
                        document.frm.action="RegisterServlet";
                        document.frm.submit();
                    }
                }
                
                function checkUserName(){
                    var uname=document.getElementById("usernameId");
                    var span=document.getElementById("userSpanId");
                    if(uname.value.trim().length==0){
                        span.innerHTML="<font color='red'>用户名不能为空啊!</font>";
                        return false;
                    }else{
                        span.innerHTML="√";
                        return true;
                    }
                }
                
                function checkPwd(){
                    var pwd=document.getElementById("pwdId");
                    var span=document.getElementById("pwdSpanId");
                    if(pwd.value.trim().length==0){
                        span.innerHTML="密码不能为空";
                        return false;
                    }else{
                        span.innerHTML="√";
                        return true;
                    }
                }
                
                function checkTwoPwd(){
                    var pwd=document.getElementById("pwdId");
                    var confPwd=document.getElementById("confPwdId");
                    
                    var pwdspan=document.getElementById("pwdSpanId");
                    var confpwdSpan=document.getElementById("confPwdSpanId");
                    
                    if(pwd.value==confPwd.value){
                        return true;
                    }else{
                        confpwdSpan.innerHTML="两次密码不一致";
                        
                        return false;
                    }
                }
                
            </script>
        </body>
    </html>
  • 相关阅读:
    poj 2391 Ombrophobic Bovines
    混合欧拉回路poj 1637 Sightseeing tour
    POJ1149-PIGS
    C
    B
    A
    C
    B
    A
    O
  • 原文地址:https://www.cnblogs.com/tytr/p/5897098.html
Copyright © 2020-2023  润新知