效果图
结构
<button>点击</button>
<div></div>
js
var div = document.querySelector('div');
var btn = document.querySelector('button');
var timer = 5;
btn.addEventListener('click', function ()
{
// console.log(window.location.href);
location.href = 'https://blog.csdn.net/chuan0106';
})
fn();
setInterval(fn, 1000)
function fn ()
{
if (timer == 0)
{
location.href = 'https://blog.csdn.net/chuan0106';
} else
{
div.innerHTML = '您将在' + timer + '秒后跳转页面';
timer--;
}
}