功能案例页面在五秒后跳转
使用js功能,通过定时器每次进行减一秒!最终实现跳转!
<!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>
<button>点击</button>
<div></div>
<script>
var btn = document.querySelector('button');
var div = document.querySelector('div');
btn.addEventListener('click', function() {
// location.href = 'http://www.itcast.cn';
var timer = 5;
setInterval(countDown, 1000);
function countDown() {
if (timer == 0) {
location.href = 'href="https://blog.csdn.net/weixin_46002223"';
} else {
div.innerHTML = '您将在' + timer + '秒内跳转首页';
timer--;
}
}
})
</script>
</body>
</html>