<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>js-手机发送短信倒计时</title>
<style>
button{
width: 100px;
height: 30px;
border: none;
}
input{
outline: none;
}
</style>
<script>
window.onload = function(){
function $(id){ return document.getElementById(id); }
$('btn').onclick = function(){
var that = this;
that.disabled = true;
var count = 5;
var timer = setTimeout(fn,1000);
function fn(){
count--;
if(count>0){
that.innerHTML = "剩余时间"+ count +"s";
setTimeout(fn,1000);
}else{
that.innerHTML ="重新发送短信";
that.disabled = false;
}
}
}
}
</script>
</head>
<body>
<div class="box">
<input type="text" id="txt">
<button id="btn" >点击发送短信</button>
</div>
</body>
</html>
转载自:https://www.jb51.net/article/104653.htm