jQuery实现发送短信验证码后60秒倒计时

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4 <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
 5 <script type="text/javascript"> 
 6 var countdown=60; 
 7 function settime(obj) { 
 8     if (countdown == 0) { 
 9         obj.removeAttribute("disabled");    
10         obj.value="免费获取验证码"; 
11         countdown = 60; 
12         return;
13     } else { 
14         obj.setAttribute("disabled", true); 
15         obj.value="重新发送(" + countdown + ")"; 
16         countdown--; 
17     } 
18 setTimeout(function() { 
19     settime(obj) }
20     ,1000) 
21 }
22    
23 </script>
24 <body> 
25 <input type="button" id="btn" value="免费获取验证码" onclick="settime(this)" /> 
26    
27 </body>
28 </html>

 

posted @ 2016-06-02 16:20  魔流剑  阅读(489)  评论(0编辑  收藏  举报