获取短信验证码js

$( ".form-data"). delegate( ".send", "click", function () {
         var phone = $( "#tel"). val();
         if (phone == "") {
             alert( '请先填写手机号')
             $( "#tel"). css( "background-color", "#ff2f28");
             return false;
         }
         $(this). hide();
         $. ajax({
             url: "/sendsms",
             type: "get",
             dataType: 'json',
             data: {phone: phone },
             async: false,
             success: function ( data) {
                 console. log(data)
                 if (data.status == 0) {
                     settime();
                 } else {
                     alert(data.msg)
                     settime();
                 }
             },
             error: function () {
                 alert( '网络忙');
                 settime();
             }
         });
     })
     var countdown = 120;
     function settime() {
         if (countdown == 0) {
             $( ".time"). attr( "class", "time hide");
             $( ".time"). text( "120s");
             $( ".send"). css( 'display', 'block');
             countdown = 120;
             return false;
         } else {
             $( ".time"). removeClass( 'hide');
             $( ".time"). text( "重新发送(" + countdown + "s)");
             countdown --;
         }
         setTimeout( function () {
             settime();
         }, 1000);
     }

你可能感兴趣的:(js)