jQuery 点击获取验证码按钮及倒计时功能
1.具体思路
点击获取验证码按钮 ―> 调用获取验证码接口(忽略)―>获取验证码按钮切换到不可点击状态,按钮背景色呈灰色,按钮文字呈现为“倒计时秒数+后可重新获取”―> 倒计时60s后按钮恢复可点击状态,按钮背景呈橙色,按钮文字呈现为“重新发送”
2.HTML代码
<button type="button" class="feachBtn">获取验证码</button>
3.JS代码
// 点击获取验证码操作 $('.feachBtn').click(function() { let count = 60; const countDown = setInterval(() => { if (count === 0) { $('.feachBtn').text('重新发送').removeAttr('disabled'); $('.feachBtn').css({ background: '#ff9400', color: '#fff', }); clearInterval(countDown); } else { $('.feachBtn').attr('disabled', true); $('.feachBtn').css({ background: '#d8d8d8', color: '#707070', }); $('.feachBtn').text(count + '秒后可重新获取'); } count--; }, 1000); } });
4.效果图
总结
相关推荐
85477104 2020-11-17
EdwardSiCong 2020-11-23
hhanbj 2020-11-17
81427005 2020-11-11
seoppt 2020-09-13
honeyth 2020-09-13
WRITEFORSHARE 2020-09-13
84483065 2020-09-11
momode 2020-09-11
85477104 2020-08-15
83510998 2020-08-08
82550495 2020-08-03
tthappyer 2020-08-03
84901334 2020-07-28
tthappyer 2020-07-25
TONIYH 2020-07-22
tztzyzyz 2020-07-20
83510998 2020-07-18
81463166 2020-07-17