js 短信验证码 计时器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
$(function(){
    getMsg(); //页面加载完成之后执行
})
 function getMsg(){
                //注册按钮的点击事件
        $("#smsBtn").on("click", function(){
             $("#smsBtn").off(); //解除绑定,防止重复点击
              
             //dosomething
             //1.校验
             if(checkValue()){
                 getMsg(); //重新注册
                         return false;
                }
             //2.发送验证码
             sendMsg();
              var _this=$(this);
             var i = 10;
                    //定义计时器
                   var timer = setInterval(function () { 
                 _this.val(i);
                 i--;
                 if (i < 0) {
                     clearInterval(timer);  //清除计时器
                     _this.val('获取验证码');
                     getMsg();
                 }
             }, 1000);
        })
    }

  

posted @   未来--  阅读(585)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示