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

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

 

 

mark。

原文:http://www.open-open.com/code/view/1432601256051

posted @ 2016-10-26 15:07  阿星喵  阅读(220)  评论(0编辑  收藏  举报