页面延迟跳转
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script>
window.onload = function () {//加载事件
setTimeout(change, 1000);
}
function change() {
var times = document.getElementById("time").innerHTML;//获取秒
times--;
if (times < 1) {//如果秒数小于1,跳转页面,否则,将现在的秒数赋值给id为time的span控件,再执行一次setTimeout事件
window.location.href = "HtmlPage2.html";
}
else {
document.getElementById("time").innerHTML = times;
setTimeout(change, 1000);
}
}
</script>
</head>
<body>
服务器忙啊,还有<span id="time" style="color:red;">5</span>秒跳转页面
</body>
</html>
新手笔记,怕以后忘记,留着以后复习用的,请多多指教