标题:求大神解答,为什么定义的 st 返回值永远为真,控制不了表单提交啊,帮帮忙 ...
只看楼主
l3545375
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2014-9-26
结帖率:0
已结贴  问题点数:20 回复次数:1 
求大神解答,为什么定义的 st 返回值永远为真,控制不了表单提交啊,帮帮忙啊!
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script language="javascript">
function gspan(obj){
    while(true){
        if(obj.nextSibling.nodeName!="SPAN"){
            obj=obj.nextSibling;
        }else{
            return obj.nextSibling;
        }
    }
}
function check(obj,info,fun){
    var sp=gspan(obj);
    obj.onfocus=function(){
        
        sp.innerText=info;
        sp.className='sta2';
    }
    obj.onblur=function(){
        
        if(fun(this.value)){
            
            sp.innerText='输入正确';
            sp.className='sta3';
            //window.alert(regs());
            //window.alert(stas);
        }else{
            window.alert(regs());
            sp.innerText=info;
            sp.className='sta4';
            //un.focus();
        }
    }
    /*if(click=='click'){
        obj.onblur();
    }*/
}
onload=regs

function regs(){
    var st=true;
    var un=document.getElementsByName('uname')[0];
    var pw1=document.getElementsByName('pwd1')[0];
    var pw2=document.getElementsByName('pwd2')[0];
    var em=document.getElementsByName('email')[0];
   
    check(un,'请输入5-15的数字',function(val){
        if(val.match(/^\S+$/)&&val.length>=5&&val.length<=15){
            
            return true;
        }else{
            st=false;
            //window.alert(regs());
            window.alert(st);
            return false;
        }
    });
    check(pw1,'请输入6位密码',function(val){
        if(val.match(/^\S+$/)&&val.length==6){
            return true;
        }else{
            st=false;
            return false;
        }
    });
    check(pw2,'请再次输入密码,希望和上面一致',function(val){
        if(val.match(/^\S+$/)&&val.length==6&&val==pw1.value){
            return true;
        }else{
            st=false;
            return false;
        }
    });
    check(em,'请输入正确的邮箱地址',function(val){
        if(val.match( /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/)){
            return true;
        }else{
            st=false;
            //window.alert(abcd);
            return false;
        }
    });
   
    return st;
}
</script>
<style>
.sta1{
    color:#999;
}
.sta2{
    color:#0C6;
}
.sta3{
    color:#C36;
}
.sta4{
    color:#FC0;
}
</style>
</head>

<body>
<form method="post" action="text1.html"  onSubmit="return regs()">
用户名:<input type="text" name="uname" value="" /><span id="one" class="sta1">请输入用户名</span><br />
密码:<input type="password" name="pwd1"/><span id="two" class="sta1">请输入密码</span><br />
重复密码:<input type="password" name="pwd2" /><span id="three" class="sta1">再次输入密码</span><br />
邮箱:<input type="text" name="email" /><span id="four" class="sta1">请输入邮箱</span><br />
<input type="submit" value="提交" name='sub' />
</form>
</body>
</html>
搜索更多相关主题的帖子: function javascript content return title 
2014-09-26 08:05
tlliqi
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:204
帖 子:15453
专家分:65956
注 册:2006-4-27
得分:20 
楼下来答
2014-09-26 13:37



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-436583-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.031650 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved