js 读秒

<input   type="button" value="&nbsp;获取验证码&nbsp;" class="verification right" ">
$(".verification").click(function(){
    var nums = 20;
    var tel = $("#tel").val();
    if(!is_mobile(tel)){
        hint_msg('手机号码不正确');
        return;
    }else{
    $(".verification").css('border','1px solid #B7B2B2').css("background-color","#B7B2B2").prop('disabled',true);
    $(".verification").val(" "+nums+'秒后重试'+" ");
     var timer = setInterval(Byoyomi,1000);
     function Byoyomi() {
         nums--;
         if (nums > 0) {
             $(".verification").val(" "+nums+'秒后重试'+" ");
         } else {
             clearInterval(timer); //清除js定时器
             $(".verification").css('background-color','#FF8000').css('border','1px solid #FF8000').prop('disabled',false);
             $(".verification").val(" "+"获取验证码"+" ");
             nums = 20; //重置时间
        }
    }
   }
});

 

posted @ 2018-02-06 17:17  小猪哥哥  阅读(366)  评论(0编辑  收藏  举报