欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

倒计时

程序员文章站 2022-10-17 11:29:16
Title

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