<!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>