短信验证倒计时代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
<script type="text/javascript">
window.onload=function(){
var btn=document.getElementById("btn");
var timer=null;

btn.onclick=function(){
this.disabled=true;
var count=5;
var that=this;
timer=setInterval(number,1000)
function number(){
count--;
if(count>=0){
that.innerHTML="还剩"+count+"秒";
}else{
that.innerHTML="请发送短信验证码";
that.disabled=false;
clearInterval(timer);
count=5;
}
}
}
}
</script>
</head>
<body>
<input type="text" />
<button id="btn">点击发送短信</button>

</body>
</html>

原文地址:https://www.cnblogs.com/zhaocong/p/6947201.html