JavaScript案例--五秒后自动跳转页面

image

<!DOCTYPE html>
<html>
	<head>
	<meta charset="utf-8">
	<title></title>
	<style>
		div {
			width: 300px;
			height: 100px;
			line-height: 100px;
			text-align: center;
			background-color: #abfffa;
			border-radius: 10px;
			margin: 200px auto;
		}
	</style>
	</head>
	<body>
		<div></div>
		<script>
			let div = document.querySelector('div');
			let timer = 5;
			fn();
			setInterval(fn, 1000)
			function fn() {
				if (timer == 0) {
					location.href = 'https://www.cnblogs.com/Eamon-18';
				} else {
					div.innerHTML = '页面将在' + timer + '秒之后自动跳转';
					timer--;
				}
			}
		</script>
	</body>
</html>

posted @ 2022-04-25 21:33  秋弦  阅读(1117)  评论(0编辑  收藏  举报