使用javascript实现页面定时跳转总结篇

时间:2013-09-21    点击:65   
下面对使用JavaScript实现页面定时跳转(也称倒计时跳转)做一下总结,各种定时跳转代码记录如下:

(1)使用 setTimeout 函数实现定时跳转(如下代码要写在body区域内)
复制代码 代码如下:

<script type="text/javascript">
// 3秒钟之后跳转到指定的页面
setTimeout(window.location.href = "http://3aj.cn/javascript/19.html", 3);
</script>

(2)html代码实现,在页面的head区域块内加上如下代码
复制代码 代码如下:

<!-- 5秒钟后跳转到指定的页面 -->
<meta http-equiv="refresh" content="5;url=http://3aj.cn/javascript/19.html" />

(3)稍微复杂点,多见于登陆之后的定时跳转
复制代码 代码如下:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js定时跳转页面的方法</title>
</head>
<body>
<script type="text/javascript">
var t = 10; // 设定跳转的时间
setInterval("refer()", 1000); // 启动1秒定时
function refer(){
if (t == 0) {
location = "http://3aj.cn/javascript/19.html"; // 设定跳转的链接地址
}
document.getElementById('show').innerHTML = "" + t + "秒后跳转到php程序员教程网"; // 显示倒计时
t--; // 计数器递减
}
</script>
<span id="show"></span>
</body>
</html>
用RadioButten或CheckBox实现div的显示与隐藏
JS.GetAllChild(element,deep,condition)使用介绍
JS.findElementById()使用介绍
JS.getTextContent(element,preformatted)使用介绍
javascript实现原生ajax的几种方法介绍
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 Product All Rights Reserved