<!DOCTYPE html>
<html>
<head>
<meta name="" content="" charset="utf-8" />
<title>clearInterval</title>
</head>
<body>
<script type="text/javascript">
window.addEventListener('load', function() {
var btn = document.querySelector('button');
var div = document.querySelector('div');
btn.addEventListener('click', function() {
location.href = 'http://www.baidu.com';
})
var timer = 5;
setInterval(function() {
if(timer == 0) {
// location.herf = 'http://www.itcast.cn';
location.href = 'http://www.baidu.com';
} else {
div.innerHTML = '您将在' + timer + '秒后跳转到首页';
timer--;
}
}, 1000);
})
</script>
<button>跳转</button>
<div> </div>
</body>
</html>