js自動倒數計時程式碼,倒數計時完畢時自動停止迴圈

James·wang發表於2024-07-19
            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);

相關文章