发送验证码后倒计时功能实现

 1 function settime(obj) {
 2     if (countdown == 0) {
 3         obj.removeAttribute("disabled");
 4         var txt = "获取验证码";
 5         $(obj).text(txt);
 6         countdown = 60;
 7         return;
 8     } else {
 9         obj.setAttribute("disabled", true);
10         var txt = "重新发送(" + countdown + ")";
11         $(obj).text(txt);
12         countdown--;
13     }
14 
15     setTimeout(function() {
16             settime(obj)
17     }, 1000);
18 }

<button class="btn_yan" onclick="settime(this); return false;">获取验证码</button>

<script>

var countdown = 60;

</script>

 

posted on 2017-01-19 09:57  dongruiha  阅读(362)  评论(0编辑  收藏  举报

导航