clearInterval濡備綍閬垮厤鍐呭瓨娉勯湶
浣跨敤clearInterval鏃讹紝搴旇纭繚鍦ㄤ笉闇€瑕佷娇鐢ㄥ畾鏃跺櫒鏃跺皢鍏舵竻闄ゃ€傚鏋滀笉娓呴櫎瀹氭椂鍣紝瀹氭椂鍣ㄤ細涓€鐩磋繍琛岋紝瀵艰嚧鍐呭瓨娉勯湶銆?/p>
鍙互鍦╟learInterval涔嬪墠灏嗗畾鏃跺櫒璧嬪€肩粰涓€涓彉閲忥紝鐒跺悗鍦ㄤ笉闇€瑕佹椂浣跨敤clearInterval娓呴櫎瀹氭椂鍣紝濡備笅鎵€绀猴細
// 鍒涘缓瀹氭椂鍣?/span>
let timer = setInterval(function() {
console.log('瀹氭椂鍣ㄨ繍琛屼腑...');
}, 1000);
// 娓呴櫎瀹氭椂鍣?/span>
clearInterval(timer);
鍙﹀锛屽鏋滃湪浣跨敤瀹氭椂鍣ㄧ殑浠g爜鍧楁墽琛屽畬鎴愬悗灏变笉鍐嶉渶瑕佸畾鏃跺櫒锛屽彲浠ヨ€冭檻浣跨敤setTimeout浠f浛setInterval锛屽洜涓簊etTimeout鍙細鎵ц涓€娆★紝涓嶄細閲嶅瑙﹀彂銆?/p>
相关问答