js自动倒计时代码,倒计时完毕时自动停止循环

            const getCodeBtn =。。。;
            let countdown = 60;
            let intervalId;
            getCodeBtn.attr("disabled","disabled");
            intervalId = setInterval(function () {
                if (countdown === 0) {
                    getCodeBtn.text("获取验证码");
                    getCodeBtn.removeAttr("disabled");
                    clearInterval(intervalId);
                } else {
                    countdown--;
                    getCodeBtn.text(countdown);
                    getCodeBtn.disabled = true;
                }
            }, 1000);

 

posted @ 2024-07-19 11:32  James·wang  阅读(28)  评论(0编辑  收藏  举报