html计时发送验证码功能的实现

        function countdown()
        {
            var time=60;
            setTime=setInterval(function(){
                if(time<=0){
                    clearInterval(setTime);
                    $('.sendcode').attr("disabled", false);
                    $('.sendcode').text("发送验证码");
                    return;
                }
                time--;
                $('.sendcode').text(time+'s后重试');
            },1000);
        }
        $('.sendcode').click(function () {
            $('.error_msg').html("");
            var mobile = $('#mobile').val();
            $.ajax({
                type: 'POST',
                url: 'send_code_for_admin_login',
                data: {mobile:mobile},
                dataType: 'json',
                success:function(data){
                    if (data.code != 0) {
                        $('.error_msg').html("<font color='red'>"+data.message+"</font>");
                    }

                    if (data.code == 30001 || data.code == 0) {
                        $('.sendcode').attr("disabled", "disabled");
                        countdown();
                    }
                },
            });
        });