本文主要和大家分享js获取短信验证码按钮倒计时代码,希望能帮助到大家。
(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中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号