Home >Web Front-end >JS Tutorial >js implementation of obtaining SMS verification code example

js implementation of obtaining SMS verification code example

小云云
小云云Original
2018-03-30 17:31:043940browse

This article mainly shares with you examples of js implementation for obtaining SMS verification codes. It is mainly shared with you in the form of code. I hope it can help you.

$(".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("<em>120</em>s");
             $(".send").css(&#39;display&#39;,&#39;block&#39;);
             countdown = 120;
             return false;
         } else {
             $(".time").removeClass(&#39;hide&#39;);
             $(".time").text("重新发送("+ countdown+"s)");
             countdown--;
         }
         setTimeout(function () {
             settime();
         }, 1000);
     }

Related recommendations:

js gets SMS verification code button countdown code

js implements SMS verification code countdown function

How to use php to send SMS verification code

The above is the detailed content of js implementation of obtaining SMS verification code example. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn