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('display','block'); countdown = 120; return false; } else { $(".time").removeClass('hide'); $(".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!