<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<input type="text" placeholder="输入手机号">
<input type="button" value="获取验证码">
<script>
var num = document.body.firstElementChild;
var btn = num.nextElementSibling;
btn.onclick = function (){
if (num.value != ""){
var time;
var count = 5;
this.disabled = true;
time = window.setInterval(()=>{
btn.value = count + "秒后重新获取";
if (count == 0){
window.clearInterval(time);
count = 5;
btn.disabled = false;
btn.value = "重新获取";
}
count--;
},1000);
}
}
</script>
</body>
</html>
JavaScript实现获取短信效果
最新推荐文章于 2023-11-25 06:36:18 发布