console
let getCode = document.getElementById('getCode');
getCode.onclick = function () {
if(this.mark) {
return;
}
let t = 60;
this.innerText = '重新发送(60)';
this.classList.add('disabled');
this.mark = true;
this.timer = setInterval(function () {
t--;
this.innerText = '重新发送(' + t + ')';
if(t == 0) {
this.innerText = '重新发送';
this.classList.remove('disabled');
this.mark = false;
clearInterval(this.timer);
}
}.bind(this), 1000)
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
</head>
<body>
<div id="getCode" class="cusBtn">发送验证码</div>
</body>
</html>
.cusBtn {
display: inline-block;
padding: 10px 15px;
background-color: #ffba00;
color: #fff;
border-radius: 5px;
cursor: pointer;
}
.disabled {
cursor: no-drop;
background-color: #bababa;
}