jquery 倒计时 60秒 短信 验证码 js ajax 获取

 

$(function () {

    var wait=60;
    function time( o ){

        if (wait == 0) {
            o.toggleClass('bg-lv');
            o.removeAttr("disabled");   
            o.val("获取验证码");
            wait = 60;

        } else { 
            o.removeClass('bg-lv');
            o.attr("disabled",true);
            o.val("重新发送(" + wait + ")");
            wait--;
            setTimeout(function() {
            time(o);
            }, 1000)
        }
    }

    $("#getCode").click(function(){

        var formData = $('#form').serialize();
        $.ajax({
            url:"{:url('login/index')}",
            data:formData,
            dataType:"json",
            type:"post",
            success:function(r){
                if(r.check==1){
                    time($("#getCode"));
                    alert(r.msg);
                }else{
                    alert(r.msg);
                }
            }
        })
        return false;
    });  
    
});  

 

posted @ 2018-04-03 09:43  WilliamShaw  阅读(276)  评论(0编辑  收藏  举报