
function invokeSettime(obj){
    var countdown=60;
    settime(obj);
    function settime(obj) {
        if (countdown == 0) {
            $(obj).attr("disabled",false);
            $(obj).text("获取验证码");
            countdown = 60;
            return;
        } else {
            $(obj).attr("disabled",true);
            $(obj).text("(" + countdown + ") s 重新发送");
            countdown--;
        }
        setTimeout(function() {
                settime(obj) }
            ,1000)
    }
}

jQuery(document).ready(function () {
   $('#send_code').click(function () {
       let captcha = $('#captcha').val();
       let phone = $('#phone').val();
       let R_tel = /^1[3|4|5|6|7|8|9][0-9]{9}$/;
       if (!R_tel.test(phone)) {
           alert('手机号格式不正确');
           return;
       }
       if (!captcha) {
           alert('验证码必须');
           return;
       }
       let data={captcha, phone};
       let ob=this;
       $(this).attr("disabled",true);
       $.get('/register/sms',data, function (data) {
           alert('发送成功');
           invokeSettime(ob);
       }).fail(function () {
           $('#send_code').attr("disabled",false);
           $('#captcha').val('');
           $('#captcha_img').trigger('click');
       });
   }); 
});