<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
box-sizing: border-box;
}
.div {
position: relative;
height: 400px;
}
#btn {
height: 50px;
width: 100px;
position: absolute;
top: 50%;
left: 50%;
padding: 10px;
transform: translate(-50%,-50%);
}
</style>
</head>
<body>
<div class="div">
<input type="button" id="btn" value="获取验证码" />
</div>
<script type="text/javascript">
let wait = 60;
function time(val){
if(wait == 0) {
val.removeAttribute("disabled");
val.value = "获取验证码";
wait = 60;
} else{
val.setAttribute("disabled",true);
val.value = "重新发送("+wait+")"
wait--;
}
setTimeout(()=>{
time(val)
},1000)
}
document.getElementById("btn").onclick = function(){
time(this)
}
</script>
</body>
</html>