2 qq 27370819 qq_27370819 于 2016.04.15 11:14 提问

为甚么用js验证表单,style时间太短
 <%@ page contentType="text/html;charset=utf-8"%>
<%@ page import="java.sql.*"%>
<!DOCTYPE html>
<html>
<head>
    <title>欢迎加入CM</title>
    <style type="text/css" media="screen">
        .div{
            padding: 20px;
            width: 600px;
            height: 600px;
            margin:0 auto ;
            position:relative; background-color: #555;
        }
        img{
            width: 80px;
            height: 80px;
        }
        .div .img{
            width: 80px;
            height: 80px;
            position:absolute; left:30px; top:10px; 
        }
        .re{
            margin-left: 150px;
            text-align: left;
        }
        .form{
            width: 180px;
            height: 25px;
            margin:5px auto;
        }
        label{
            color: red;
            font-size: 12px;
            visibility: hidden;
            display: none;
        }
    </style>
    <script>

        function check() {
            var username=document.getElementById('UserName').value;
            var nickname=document.getElementById('NickName').value;
            var email=document.getElementById('Email').value;
            var phone=document.getElementById('PhoneNumber').value;
            var password=document.getElementById('Password').value;
            var rpassword=document.getElementById('RPassword').value;
            var em=/^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$ /;
            var ph=/^(13[0-9]{9})|(15[89][0-9]{8})$/;
            var pw=/^[a-zA-Z0-9_]/;

            if (username.replace(/(^s*)|(s*$)/g, "").length ==0) {
                var label1=document.getElementById('label1');
                label1.style.visibility="visible";
                label1.style.display="";
            }else
            if (nickname.replace(/(^s*)|(s*$)/g, "").length ==0) {
                document.getElementById('label2').style.visibility="visbile";
                document.getElementById('label2').style.display="";
            }else
            if (email.replace(/(^s*)|(s*$)/g, "").length ==0||em.test(email)) {
                document.getElementById('label3').style.visibility="visbile";
                document.getElementById('label3').style.display="";
            }else
            if (phone.replace(/(^s*)|(s*$)/g, "").length ==0||ph.test(phone)) {
                document.getElementById('label4').style.visibility="visbile";
                document.getElementById('label4').style.display="";
            }else
            if (password.replace(/(^s*)|(s*$)/g, "").length ==0||pw.test(password)||password.length<6&&password.length>18) {
                document.getElementById('label5').style.visibility="visbile";
                document.getElementById('label5').style.display="";
            }else
            if (rpassword!=password) {
                document.getElementById('label6').style.visibility="visbile";
                document.getElementById('label6').style.display="";
            }
        }

    </script>
</head>
<body>
<div class="div">
<div class="img">
    <a href="index.jsp"><img src="images/logo.gif" alt="logo" /></a>    
</div>
<div class="re">

    <form action="" method="post">
        <h2>Welcome TO Join CM</h2>
        <p><input type="text" class="form" id="UserName" placeholder="设置用户名"></input><nobr><label  id="label1">x不为空</label></nobr></p>
        <p><input type="text" class="form" id="NickName" placeholder="设置昵称"></input><nobr><label  id="label2">x不为空</label></nobr></p>
        <p><input type="text" class="form" id="Email" placeholder="设置Email"></input><nobr><label  id="label3">x不为空,Email格式有误</label></nobr></p>
        <p><input type="text" class="form" id="PhoneNumber" placeholder="设置手机号"></input><nobr><label  id="label4">x不为空,格式有误</label></nobr></p>
        <p><input type="text" class="form" id="Password" placeholder="设置密码"></input><nobr><label  id="label5">x不为空,6-18位,只能包含数字,字母,下划线</label></nobr></p>
        <p><input type="text" class="form" id="RPassword" placeholder="确认密码"></input><nobr><label id="label6">x两次密码不一致</label></nobr></p>
        <p><input type="submit" id="button" value="注册" onclick="check()"></input></p>
    </form>
</div>  
</div>
</body>
</html>

2个回答

CSDNXIAOD
CSDNXIAOD   2016.04.15 11:22

js验证表单
js验证表单
js验证表单
----------------------biu~biu~biu~~~在下问答机器人小D,这是我依靠自己的聪明才智给出的答案,如果不正确,你来咬我啊!

xxmvzeetbb
xxmvzeetbb   2016.10.08 01:41

="java.sql.*"%>
<!DOCTYPE html>


欢迎加入CM
<br> .div{<br> padding: 20px;<br> width: 600px;<br> height: 600px;<br> margin:0 auto ;<br> position:relative; background-color: #555;<br> }<br> img{<br> width: 80px;<br> height: 80px;<br> }<br> .div .img{<br> width: 80px;<br> height: 80px;<br> position:absolute; left:30px; top:10px; <br> }<br> .re{<br> margin-left: 150px;</p>
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!