(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); }); } }); })();
效果图:
相关推荐:
js实现短信验证码倒计时实例分享
怎么用php实现短信验证码发送
js实现短信验证码
以上就是js获取短信验证码按钮倒计时代码的详细内容。
