js验证按钮
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<input type="text">
<button>发送验证码</button>
<script>
var inp = document.getElementsByTagName("input")[0];
var btn = document.querySelector("button");
btn.onclick = function () {
var n = 10;
var timer = setInterval(function () {
if (n <= 0) {
n = 0;
btn.disabled = false;//禁用按钮功能关闭
btn.innerHTML = "重新发送";
clearInterval(timer);//关闭定时器
} else {
n--;
btn.disabled = true;//禁用按钮功能开启
btn.innerHTML = n + "s之后重新发送";
console.log(n);
}
}, 1000);
}
</script>
</body>
</html>