求大神解答,为什么定义的 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>