js经典实例----倒计时页面跳转效果

<h2>
			<span id="container">5</span>秒钟后页面即将跳转
		</h2>
		<script>
			let num = 5;

			var clock = setInterval(function() {
				num = --num;
				if (num <= 0) {
					clearInterval(clock)
					location = 'http://www.baidu.com'
				}
				document.getElementById('container').innerHTML = num
			}, 1000)
		</script>
上一篇:js实现懒加载原理


下一篇:计时器