js-登陆验证码的案列
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
输入验证号码:<input type="text"><button>发送</button>
<script>
var btn = document.querySelector('button')
var time = 3
var timer = btn.addEventListener('click', function() {
btn.disabled = true
setInterval(function(){
if(time == 0) {
//
// btn.innerHTML = '发送';
clearInterval(timer)
btn.disabled = false;
btn.innerHTML = '发送';
time = 3
} else{
btn.innerHTML = '还剩'+ time +'秒';
time--;
}
}, 1000)
})
</script>
</body>
</html>