This article mainly shares with you the js countdown code for getting the SMS verification code button. I hope it can help everyone.
(function(){ // 快速咨询 $('#getCode').click(function() { var mobile = $('#mobile').val();//手机号码的值 var _this = $(this); var mobileReg = /^1[3|4|5|7|8]\d{9}$/; //手机号正则 var phoneflag = mobileReg.test(mobile); if (!phoneflag) { alert('手机号码格式不正确!'); } else { //User/getCode.html这个是后台接口 $.post("/User/getCode.html", { mobile: mobile }, function(data) { _this.attr("disabled", "disabled"); _this.css({background:"#eee"});//设置不可点颜色 var val = parseInt(_this.val()); var time = 60; _this.val(time + " S"); time--; var timer = setInterval(function() { val = time + " S"; _this.val(val); if (time > 0) { time--; } else { //原始颜色 _this.val("获取验证码").removeAttr("disabled").css({background:"#66CCFF"});; clearInterval(timer); } }, 1000); }); } }); })();
Rendering:
Related recommendations:
js implementation of SMS verification code countdown example sharing
How to use php to implement SMS verification code sending
JS to implement SMS verification code
The above is the detailed content of js gets SMS verification code button countdown code. For more information, please follow other related articles on the PHP Chinese website!