var ipn = document.getElementById('ipn');
var txt = document.getElementById('text');
ipn.onfocus = function() {
txt.innerHTML = '使用6-18位字母数字、支持中文';
}
ipn.onblur = function() {
var reg = /^[\u4e00-\u9fa5a-zA-Z0-9]{6,12}$/;
var result = reg.test(ipn.value);
if(result == true) {
txt.innerHTML = '通过';
} else {
txt.innerHTML = '格式错误';
}
}
//==================
var ipn1 = document.getElementById('ipn1');
var txt1 = document.getElementById('text1');
ipn1.onfocus = function() {
txt1.innerHTML = '使用6-18位字母数字';
}
ipn1.onblur = function() {
var reg1 = /^[A-Za-z0-9]{6,12}$/;
var result1 = reg1.test(ipn1.value);
if(result1 == true) {
txt1.innerHTML = '通过';
} else {
txt1.innerHTML = '格式错误';
}
}
//==================
var ipn2 = document.getElementById('ipn2');
var txt2 = document.getElementById('text2');
ipn2.onfocus = function() {
txt2.innerHTML = '请再次输入密码';
}
ipn2.onblur = function() {
if(ipn1.value == ipn2.value) {
txt2.innerHTML = '验证通过';
} else {
txt2.innerHTML = '两次密码输入不一致';
}
}
//==================
var ipn3 = document.getElementById('ipn3');
var txt3 = document.getElementById('text3');
ipn3.onfocus = function() {
txt3.innerHTML = '请输入11位手机号';
}
ipn3.onblur = function() {
var reg3 = /^1[356789]\d{9}$/;
var result3 = reg3.test(ipn3.value);
if(result3 == true) {
txt3.innerHTML = '输入正确';
} else {
txt3.innerHTML = '手机号格式错误';
}
}
//==================
var btng = document.querySelector('.btng');
var a = Math.floor(Math.random() * (9999 - 1000 + 1) + 1000);
console.log(a);
btng.onclick = function() {
if(btng.innerHTML == '获取验证码') {
btng.innerHTML = "60秒之后获取";
alert('您的验证码:' + a);
//用来当秒数的
var i = 59;
//执行
var xh = setInterval(function() {
btng.innerHTML = i + "秒之后获取"
i--;
if(i == 0) {
clearInterval(xh);
btng.innerHTML = "获取验证码"
}
}, 1000);
}
}
//=================
var btn = document.getElementById('btn');
var ipn4 = document.getElementById('ipn4');
var box = document.querySelector('.box')
btn.onclick = function() {
if(ipn4.value == a) {
alert('验证通过,正在跳转....');
box.style.display = 'block';
} else {
alert('验证失败,重新尝试')
}
}
//============欢迎
var hy = document.getElementById('hy');
var ip = document.querySelector('#ipn');
console.log(ip.value)
hy.innerHTML = '欢迎回来' + ip.value;