效果展示图
短信
需求分析
输入框内输入0505弹出验证成功
点击发送短信,按钮禁用并出现一分钟倒计时
功能实现
检验input里的值是否正确,正确弹出正确,错误弹出错误
点击发送短信,改变button里的内容,利用计时器,number从60开始,每执行一次减一,直到为0,改变button内容回到初始,禁用解除
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div{
height: 100px;
width: 300px;
margin: 0 auto;
margin-top: 200px;
}
</style>
</head>
<body>
<div>
<input type="text" placeholder="请输入验证码" class="in" >
<button class="yanzheng">点击发送验证码</button>
<button class="queren">请点击确认</button>
</div>
<script>
var number=60;
oy=document.querySelector('.yanzheng');
oq=document.querySelector('.queren');
oy.onclick=function(){
move=setInterval(function(){
if(number>0){
oy.disabled=true;
oy.innerHTML="请在"+number+"秒后重试";
number--;
}
else{
clearInterval(move)
number=60;
oy.disabled=false;
oy.innerHTML="点击发送验证码";
}
},1000)
}
oq.onclick=function(){
var oinput=document.querySelector('.in').value;
console.log(typeof(oinput))
if(oinput==="0505"){
alert('验证成功');
}
else{
alert('验证失败!')
}
}
</script>
</body>
</html>