快捷导航

有三个问题在最底下

form验证表单            *{            margin:0;            padding:0;            font-family: "微软雅黑";            font-size:12px;        }        label{            font-weight: bold;            margin-right:20px;            text-align:right;        }        input{            width:300px;            height:30px;            -webkit-box-sizing: border-box;            -moz-box-sizing: border-box;            box-sizing: border-box;            -webkit-border-radius:5px;            -moz-border-radius:5px;            border-radius:5px;        }        p{            visibility: hidden;            display: block;            margin-top:5px;            margin-left:50px;            color: rgb(220,220,220);            font-size:10px;        }        .box{            margin-bottom: 20px;            text-align: center;        }        .btn{            width:70px;            height:30px;            background:rgb(45,121,183);            color: #fff;            text-align: center;            line-height: 30px;            box-sizing: border-box;            border:0;            border-radius: 5px;        }                            名称                        必填,长度为4—16个字符
        
                     密码                        密码不能为空
        
                     密码确认                        密码不能为空
        
                     邮箱                        邮箱不能为空
        
                     手机                        手机号不能为空
        
                    提交        
    <script>//    //    1.通过id进行监听,显示验证信息//    2.通过id进行监听,来完成对当前任务订单效验//    3.通过点击btn按钮,来完成所有值的效验,并作出判断,进行falsevar $=function(id){    return document.getElementById(id);};//捕获焦点$("wrap").addEventListener("focus",checkFocus,true);$("wrap").addEventListener("blur",checkBlue,true);$("btn").addEventListener("click",function(){    if(/*所有时间都为true*/){        alert("注册成功");    }else{        alert("注册失败") //提示哪里出问题? }});function checkFocus(ev){    var e=ev||window.event;    var inputs=e.target||e.srcElement;    switch (inputs.id){        case "name":            $("prompt1").style.visibility="visible";            break;        case "pwd":            $("prompt2").style.visibility="visible";            break;        case "pwd2":            $("prompt3").style.visibility="visible";            break;        case "email":            $("prompt4").style.visibility="visible";            break;        default:            $("prompt5").style.visibility="visible";    }}function checkBlue(ev){    var e=ev||window.event;    var inputs=e.target||e.srcElement;    if(inputs.nodeName.toLocaleLowerCase()=="input"){        switch (inputs.id){            case "name":                checkName(inputs);                break;            case "pwd":                checkPwd(inputs);                break;            case "pwd2":                checkPwd2(inputs);                break;            case "email":                checkEmail(inputs);                break;            default:                checkPhone(inputs);        }    }}//效验(node相当于inputs)function checkName(node){    if(!node.value){        $("prompt1").innerHTML ="不能为空";        node.style.borderColor="red";    }else if(checkCount(node.value)16){        $("prompt1").innerHTML ="4-16位之间";        node.style.borderColor="red";    }else{        $("prompt1").innerHTML ="输入正确";        node.style.borderColor="green";    }}//验证4-16位function checkCount(str){    var count=0;    for(var i=0;i=0 &&str.charCodeAt()

免责声明:本内容仅代表回答者见解不代表本站观点,请谨慎对待。

版权声明:作者保留权利,不代表本站立场。

回复

使用道具 举报

参与会员1

小白表达观点啊,欢迎指错。
问一:获取焦点不应该获取form标签上的,而是input上的。当文本框失去焦点时触发对格式的判断,提交按钮判断的只是密码正确与否。
问二:我觉得你的代码可以显示。
问三:不知道):
回复

使用道具 举报

可能感兴趣的问答

发新帖
  • 微信访问
  • 手机APP