HTML+CSS+JS - 5秒钟之后跳转页面

时间:2023-03-09 19:40:50
HTML+CSS+JS - 5秒钟之后跳转页面
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="News.Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>5秒钟后自动跳转网页</title>
<!--5秒钟后自动跳转网页-->
<script type ="text/javascript" language ="javascript">
//设置初始值
var i = 5;
//获取定时器的返回值,用来清除定时器
var cleartime;
//使用定时器,第一个参数,要执行定时器的函数,第二个参数,每个多长时间进行执行,1000MS = 1S
cleartime = setInterval("fun()", 1000);
//用来执行的函数
function fun() {
if (i == 0) {
//跳转网页
window.location.href = "Default.aspx";
//清除定时器,如未清除定时器,则会变为-1,-2,-3.......
clearInterval(cleartime);
}
//显示i的值
document.getElementById("mes").innerHTML = i;
//i - 1
i--;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<p><span id ="mes">5</span></p>
</form>
</body>
</html>

全部复制,直接在页面(.aspx)保存,然后就可以运行。