js登录界面代码自用

var btn = document.getElementById("a4");
var usne = document.getElementById("username");
var psw = document.getElementById("password");
var usneTips1 = document.getElementById("username-tips1");
var usneTips2 = document.getElementById("username-tips2");
var pswTips = document.getElementById("password-tips");
var secTips = document.getElementById("success-tips");
btn.onclick = function () {
var usneValue = usne.value;
var pasValue = psw.value;
if(usneValue == ""&& pasValue==""){
noneAll();

pswTips.style.display="inline";
usneTips2.style.display="inline";

 

}else if(usneValue != ""&& pasValue==""){
noneAll();
pswTips.style.display="inline";

}else if(usneValue == ""&& pasValue!=""){
noneAll();
usneTips2.style.display="inline";

}else if(usneValue != ""&& pasValue!=""){
noneAll();
if(usneValue.length==11||checkEmil(usneValue)==true){
noneAll();
secTips.style.display="block";
window.setTimeout("https://www.yuque.com/dashboard",2000);

}else{
usneTips1.style.display="inline";
usneTips1.style.color="red";

}
}

};

 

function noneAll() {
pswTips.style.display="none";
usneTips2.style.display="none";
usneTips1.style.display="none";
}
function checkEmil(emil) {

var reg = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$"); //正则表达式
var obj = emil;
if(!reg.test(obj)){ //正则验证不通过,格式不对
console.log("fff");
return false;
}else{
console.log("ttt");
return true;
}
}

相关文章