<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript">
// location对象 --属于window对象的子对象.
// href属性:设置或获取URL地址(网址)
//加载函数
window.onload = function(){
//获取当前网页的URL地址
var url = window.location.href;
console.log(url);
//获取按钮(根据id)
var oBtn = document.getElementById("oBtn");
//调用标签的事件属性
oBtn.onclick = function(){
location.href = "https://blog.csdn.net/qq_62898618?type=blog";
};
//定时器 setTimeout();
var date = 5;
var timer = window.setInterval(function(){
var sid = document.getElementById("sid");
if(date == 0){
window.location.href = "https://blog.csdn.net/qq_62898618?type=blog";
}else{
sid.innerHTML = date;
date--;
}
},1000);
var aid = document.getElementById("aid");
aid.onclick = function(){
//关闭定时器
window.clearInterval(timer);
window.location.href = "https://blog.csdn.net/qq_62898618?type=blog";
};
};
</script>
</head>
<body>
<h2>这是小电影网站</h2>
<button id="oBtn">跳转到电影网</button>
<hr>
<h2 style="text-align: center">网页突然走丢了</h2>
<h3 style="text-align: center;"><span id="sid" style="color: red">5</span>秒之后跳转到首页<a id="aid" href = "javascript:void(0)">立刻返回首页</a></h3>
</body>
</html>
10-03
766