倒计时

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

posted @ 2018-09-06 14:40  八十易  阅读(196)  评论(0编辑  收藏  举报