js 倒计时 跳转
1. setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式。
setTimeout() 只执行 code 一次。如果要多次调用,请使用 setInterval() 或者让 code 自身再次调用 setTimeout()。
<!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>setTimeout</title>
</head>
<body>
<div id='div1'> </div> </body>
</html> <script type="text/javascript">
//设定倒数秒数
var t = ;
//显示倒数秒数
function showTime(){
t -= ;
document.getElementById('div1').innerHTML= t;
if(t==){
location.href='http://www.baidu.com';
}
//每秒执行一次,showTime()
setTimeout("showTime()",1000);
} //执行showTime()
showTime();
</script>
2.
setInterval() 方法可按照指定的周期(以毫秒计)来调用函数或计算表达式。
setInterval() 方法会不停地调用函数,直到 clearInterval() 被调用或窗口被关闭。由 setInterval() 返回的 ID 值可用作 clearInterval() 方法的参数。
<html>
<body> <input type="text" id="clock" size="" />
<script language=javascript>
var int=self.setInterval("clock()",)
function clock()
{
var t=new Date()
document.getElementById("clock").value=t
}
</script>
</form>
<button onclick="int=window.clearInterval(int)">
Stop interval</button> </body>
</html>
example :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js定时跳转页面的方法</title>
</head>
<body>
<script type="text/javascript">
var t=;//设定跳转的时间
setInterval("refer()",); //启动1秒定时
function refer(){
if(t==){
location="www.baidu.com"; //#设定跳转的链接地址
}
document.getElementById('show').innerHTML=""+t+"秒后跳转"; // 显示倒计时
t--; // 计数器递减
}
</script>
<span id="show"></span>
</body>
</html>
遇到的问题:
当将上述js 的方法 放在$(function(){......})中时, 浏览器会报 methodXX() is not defined;
应当将function(){}的定义放在 <script></script>中
js 倒计时 跳转的更多相关文章
- js 倒计时跳转
用js实现简单的倒计时结束页面跳转效果,主要用到setInterval()和clearInterval()方法,页面跳转使用window.location.href = " ".倒 ...
- js倒计时跳转链接
(function(){ var loadUrl = 'http://www.cnblogs.com/naokr/',//跳转链接 loadTime = 3000,//跳转时间 reTime = 10 ...
- js倒计时跳转jquery插件版
<script type="text/javascript" src="js/jquery1.91.min.js"></script> ...
- js倒计时跳转页面
var t=10; setInterval(function refer(){ if(t>0){ document.getElementById("em").innerHTM ...
- js倒计时跳转页面实现
- js 倒计时跳转页面
<script type="text/javascript">var i = 5; var intervalid; intervalid = setInterval(& ...
- js写的5秒钟倒计时跳转
使用js实现几秒以后倒计时跳转,这个在某些特殊情况下还是比较实用的,下面为大家介绍下具体的实现步骤,感兴趣的朋友不要错过 代码如下: <html> <head> < ...
- JS倒计时网页自动跳转代码
<title>JS倒计时网页自动跳转代码</title> <script language="JavaScript" type="text/ ...
- JS——页面倒计时跳转
Js几秒后倒计时跳转 <html><head><title>出错啦~~~</title><link href="css/login1.c ...
随机推荐
- Hadoop - Kylin On OLAP
1.概述 Apache Kylin是一个开源的分布式分析引擎,提供SQL接口并且用于OLAP业务于Hadoop的大数据集上,该项目由eBay贡献于Apache. 2.What is Kylin 在使用 ...
- java匿名类
一般情况下,我们需要声明一个类去继承一个接口,然后再new这个类,赋值给接口.但有时后这个类只会被调用一次,为了调用方便,那么就可以用匿名类来简化这个步骤. interface IKey{ void ...
- HiKey连接
http://wiki.lemaker.org/LeMaker_Hikey:FAQ/zh-hans
- [LeetCode] Number of Islands II
Problem Description: A 2d grid map of m rows and n columns is initially filled with water. We may pe ...
- [Z] 北大一牛人生物转申CS的经历
http://www.bdwm.net/bbs/bbscon.php?board=CIS&file=M.1367038121.A&num=626&attach=0&di ...
- MVC5入门
http://www.cnblogs.com/youring2/p/mvc-5-examining-the-edit-methods-and-edit-view.html
- VB6.0手册
1.Form窗体事件 Private Sub Form_Activate() '焦点在此窗口时触发 MsgBox "窗体的Activate事件" End Sub Priv ...
- 测试GeoGebra博客
已知函数 \(\textit{f}(\textit{x})=2\textit{m}\ln\textit{x}-\textit{x}^2\), \(\textit{g}(\textit{x})=\tex ...
- RESTful API 设计指南【转】
网络应用程序,分为前端和后端两个部分.当前的发展趋势,就是前端设备层出不穷(手机.平板.桌面电脑.其他专用设备......). 因此,必须有一种统一的机制,方便不同的前端设备与后端进行通信.这导致AP ...
- label标签跳出循环
出场: 首先我们来说说为什么需要label标签,虽然我们已经知道有break,continue跳出循环,但如果是多重循环那么它们就显的无能为力了,所以就出现了label这个标签来为我们服务. 我们先来 ...