<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>自动跳转页面</title>
<!--1.展示页面
2.设置定时器
2.1-->
<style>
p{
text-align:center;
}
span{
color:red;
}
</style>
</head>
<body>
<p><span id="time">5</span>秒后,自动跳转首页</p>
<script>
var time = document.getElementById("time");
var second = 5;
var timer = window.setInterval(fun, 1000);
function fun() {
second--;
time.innerHTML = second + "";
if(second <= 0){
//方法一:跳转到当前窗口
// location.href="http://www.baidu.com";
//方法二:关闭定时器,跳转到新的浏览窗口
clearInterval(timer);//关闭定时器
window.open("http://www.baidu.com");//打开新的窗口,并跳转到页面
}
}
</script>
</body>
</html>
定时器5秒后自动跳转页面
最新推荐文章于 2022-11-25 14:45:10 发布