var btnSendCode = document.getElementById('btnSendCode') function getcode() { let username = $("input[name=username]").val(); var loading = layer.load(1); $.post("{:url('frontend/Sign/sendCode')}", { username: username }, function (response) { layer.close(loading); if (response.code != 1) { layer.msg(response.msg, function () { }); return; } layer.msg(response.msg); btnSendCode.setAttribute("disabled", true); settime(60) }) }
下面是倒计时的代码
function settime(countdown) { if (countdown == 0) { btnSendCode.removeAttribute("disabled"); btnSendCode.value = "获取验证码"; } else { btnSendCode.setAttribute("disabled", true); btnSendCode.value = "重新发送(" + countdown + ")"; countdown--; } setTimeout(function () { settime(countdown) }, 1000) }
标签:function,countdown,layer,短信,username,验证码,倒计时,btnSendCode,msg From: https://www.cnblogs.com/caijiqi190731/p/16922654.html