var
sub=document.getElementById(
"sub"
);
var
txt=document.getElementsByClassName(
"txt"
);
var
li=document.getElementsByTagName(
"li"
);
document.forms.form.onsubmit=
function
(){
yan();
var
errl=document.getElementsByClassName(
"error"
).length;
if
(!errl){
return
true
;
}
return
false
;
};
function
yan(){
for
(
var
i=0;i<txt.length;i++){
txt[i].focus();
}
sub.focus();
}
for
(
var
i=0;i<txt.length;i++)
{
txt[i].index=i;
txt[i].onfocus=
function
(){
if
(
this
.parentElement.children[2]==undefined)
return
;
this
.parentElement.children[2].remove();
};
txt[i].onblur=
function
(){
switch
(
this
.index){
case
0:
if
(
this
.value==
""
){
var
s=document.createElement(
"span"
);
s.innerHTML=
"请输入账号"
;
s.className=
"error"
;
li[
this
.index].appendChild(s)
}
else
{
var
s=document.createElement(
"span"
);
s.innerHTML=
""
;
s.className=
"sucess"
;
li[
this
.index].appendChild(s)
}
break
;
case
1:
if
(
this
.value==
""
){
var
s=document.createElement(
"span"
);
s.innerHTML=
"请输入密码"
;
s.className=
"error"
;
li[
this
.index].appendChild(s)
}
else
if
(
this
.value.length<6||
this
.value.length>11) {
var
s=document.createElement(
"span"
);
s.innerHTML=
"密码错误"
;
s.className=
"error"
;
li[
this
.index].appendChild(s);
txt[
this
.index].value=
""
;
}
else
{
var
s=document.createElement(
"span"
);
s.innerHTML=
""
;
s.className=
"sucess"
;
li[
this
.index].appendChild(s)
}
break
;
case
2:
if
(
this
.value==
""
){
var
s=document.createElement(
"span"
);
s.innerHTML=
"请再次确认密码"
;
s.className=
"error"
;
li[
this
.index].appendChild(s);
txt[
this
.index].value=
""
;
}
else
if
(
this
.value!=txt[1].value){
var
s=document.createElement(
"span"
);
s.innerHTML=
"请重新输入"
;
s.className=
"error"
;
li[
this
.index].appendChild(s);
txt[
this
.index].value=
""
;
}
else
{
var
s=document.createElement(
"span"
);
s.innerHTML=
""
;
s.className=
"sucess"
;
li[
this
.index].appendChild(s)
}
break
;
case
3:
if
(
this
.value==
""
){
var
s=document.createElement(
"span"
);
s.innerHTML=
"请输入号码"
;
s.className=
"error"
;
li[
this
.index].appendChild(s)
}
else
if
(
this
.value.length!=11){
var
s=document.createElement(
"span"
);
s.innerHTML=
"号码格式错误"
;
s.className=
"error"
;
li[
this
.index].appendChild(s)
txt[
this
.index].value=
""
;
}
else
{
var
s=document.createElement(
"span"
);
s.innerHTML=
""
;
s.className=
"sucess"
;
li[
this
.index].appendChild(s)
}
break
;
case
4:
if
(
this
.value==
""
){
var
s=document.createElement(
"span"
);
s.innerHTML=
"请输入邮箱"
;
s.className=
"error"
;
li[
this
.index].appendChild(s)
}
else
{
var
s=document.createElement(
"span"
);
s.innerHTML=
""
;
s.className=
"sucess"
;
li[
this
.index].appendChild(s)
}
break
;
}
}
}