代码实现:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div></div>
<script>
var div = document.querySelector('div');
var timer = 5;
fn();
setInterval(fn, 1000);
function fn() {
if (timer == 0) {
location.href = 'https://blog.csdn.net/Jack_lzx';
} else {
div.innerHTML = timer + '秒钟之后跳转到首页';
timer--;
}
}
</script>
</body>
</html>