javascript怎么实现5秒后跳转页面
时间:2022-02-11 16:10
javascript实现5秒后跳转页面的方法:【var div = document.querySelector('div'); var time = 5; timer(); setInterval(timer, 1000) ...】。 本文操作环境:windows10系统、thinkpad t480电脑。 在很多项目开发中我们经常会需要实现页面自动跳转的效果,下面的代码实现了页面5秒后自动跳转的效果,一起来看看吧! 具体代码如下: 推荐学习:javascript视频教程 以上就是javascript怎么实现5秒后跳转页面的详细内容,更多请关注gxlsystem.com其它相关文章!<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div></div>
<script>
var div = document.querySelector('div');
var time = 5;
timer();
setInterval(timer, 1000)
function timer() {
if (time == 0) {
location.href = 'http://www.baidu.com'
} else {
div.innerHTML = '将在' + time + '秒后跳转到百度';
time--;
}
}
</script>
</body>
</html>