/**
* Created by wenguang on 2015/12/4.
*/
function checkPassword(){//
var psw=document.getElementById('psw');
var psw1=document.getElementById('psw1');
var test=document.getElementById('test2');
if(psw.value!=psw1.value){
test.innerHTML='两次密码不一致,请重新输入';
return false
}
else
return true;
}
function checkNotNull(){//判断是否为空
var user=document.getElementById('user');
var psw=document.getElementById('psw');
var psw1=document.getElementById('psw1');
if(user.value=="") {
var span0=document.getElementById('test0');
span0.innerHTML='该项不能为空';
return false;
}
else if(psw.value==""){
var span1=document.getElementById('test1');
span1.innerHTML='该项不能为空';
return false;
}
else if (psw1.value=="") {
var span2=document.getElementById('test2');
span2.innerHTML='该项不能为空';
return false;
}
else return true;
}
//绑定事件
function addEvent(obj,type,fn){
if(obj.addEventListener){
obj.addEventListener(type,fn,false);
}else if(obj.attachEvent){
obj.attachEvent('on'+type,fn);
}
}
//跨浏览器阻止默认行为
function preventDefault(evt){
var e=evt||window.event;
if(e.preventDefault){
e.preventDefault();
}else{
e.returnValue=false;
}
}
addEvent(window,'load',function(){
var fm=document.getElementById('register');
addEvent(fm,'submit',function(evt){
preventDefault(evt);
if(checkNotNull()) {
if (checkPassword()) {//如果两次密码相同则提交
fm.submit();
}
}
});
});
addEvent(window,'load',function(){//获取焦点是清空提示
var user=document.getElementById('user');
var psw=document.getElementById('psw');
var psw1=document.getElementById('psw1');
addEvent(user,'focus',function(){
var span0=document.getElementById('test0');
span0.innerHTML='';
});
addEvent(psw,'focus',function(){
var span1=document.getElementById('test1');
span1.innerHTML='';
});
addEvent(psw1,'focus',function(){
var span2=document.getElementById('test2');
span2.innerHTML='';
});
});