<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="jquery.min.js"></script>
</head>
<body>
<input type="number" class="number">
<input type="button" class="btn" id="btn" value="获取验证码">
<script>
var oBtn = document.getElementById("btn")
function getCode() {
var num = 30;
var timer = setInterval(function () {
num--
$(".btn").val(num+ ' 秒后重新获取');
if(num==0){
clearInterval(timer)
// debugger;
$(".btn").val("重新获取");
oBtn.addEventListener("click",getCode)
}else{
oBtn.removeEventListener('click', getCode);
}
},1000)
}
oBtn.addEventListener("click",getCode)
</script>
</body>
</html>