js 10秒钟倒计时
第一个:
<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>counter</title><script language="javascript" type="text/JavaScript">function Counter(nMax,nInterval){this.maxTime=nMax;this.interval=nInterval;this.objId="timer";this.obj=null;this.num=this.maxTime;this.timer=null;this.start=function(){ this.obj=document.getElementById(this.objId);if(this.num>0) setTimeout(this.run,this.interval*1000);};this.run=function(){if(myCounter.num>0) {myCounter.num--;myCounter.obj.innerHTML=myCounter.num;myCounter.timer=setTimeout(myCounter.run,myCounter.interval*1000);}else clearTimeout(myCounter.timer);};this.show=function(){document.write("<span id="+this.objId+">"+this.num+"</span>");this.obj=document.getElementById(this.objId);//alert(this.obj.innerHTML);}}</script></head><body onload="myCounter.start();"><script language="JavaScript" type="text/JavaScript">var myCounter=new Counter(10,1);</script><p>现在剩下<script language="JavaScript" type="text/JavaScript">myCounter.show();</script>秒钟!</p> |
第二个:很中庸的倒计时,我用的这个
请等待<span id="dd">10</span>秒<script type="text/javascript">function run(){ var s = document.getElementById("dd"); if(s.innerHTML == 0){ window.location.href='www.baidu.com'; return false; } s.innerHTML = s.innerHTML * 1 - 1;}window.setInterval("run();", 1000);</script> |
第三个:毫秒级的,比较紧张:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script type="text/javascript"> <!-- var duration=9900; var endTime = new Date().getTime() + duration + 100; function interval() { var n=(endTime-new Date().getTime())/1000; if(n<0) return; document.getElementById("timeout").innerHTML = n.toFixed(3); setTimeout(interval, 10); } window.onload=function() { interval(); } //--> </script><head runat="server"> <title>等待10秒</title></head><body> <form id="form1" runat="server"> <div> 现在剩下 <span id="timeout">10.000</span> 秒后 将自动跳转 </div> </form></body></html> |
js 10秒钟倒计时的更多相关文章
- js 10秒倒计时 功能
请等待<span id=</span>秒 <script type="text/javascript"> function run(){ var s ...
- 原生js 当前时间 倒计时代码
源:https://www.oschina.net/code/snippet_2318153_54763 <!DOCTYPE html> <html> <head> ...
- JS简单的倒计时(代码优化)
倒计时网上一大堆,所以也没有什么好说的,支持:1.年,月,日,天,时分秒等倒计时. JS代码如下: /* * js简单的倒计时 * @param {date,obj} 日期 对象格式 */ funct ...
- js验证码有效时间倒计时
js验证码有效时间倒计时 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type& ...
- JS实现自动倒计时
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- IOS第六天(2:10秒倒计时)
****************10秒倒计时 #import "HMViewController.h" @interface HMViewController () <UIA ...
- crontab每10秒钟执行一次
1.使用sleep 在crontab中加入 * * * * * sleep 10; /bin/date >>/tmp/date.txt* * * * * sleep 20; /bin/da ...
- 每隔10秒钟打印一个“Helloworld”
/** * 每隔10秒钟打印一个“Helloworld” */ public class Test03 { public static void main(String[] args) throws ...
- js团购倒计时函数代码
<h1>团购啦!</h1><p>还剩<span id="times"></span></p> <SCR ...
随机推荐
- test generation和MBIST
The problem of test generation Random test generation Deterministic algorithm for test generation fo ...
- html 输入框验证
JS判断只能是数字和小数点 1.文本框只能输入数字代码(小数点也不能输入)<input onkeyup="this.value=this.value.replace(/\D/g,'') ...
- 9. 星际争霸之php设计模式--代理模式
题记==============================================================================本php设计模式专辑来源于博客(jymo ...
- 将服务费用DIY到底----走出软件作坊:三五个人十来条枪 如何成为开发正规军(十)[转]
前一段时间,讲了一系列开发经理.实施经理.服务经理的工具箱:开发经理的工具箱---走出软件作坊:三五个人十来条枪 如何成为开发正规军(三) ,实施经理的工具箱--走出软件作坊:三五个人十来条枪 如何成 ...
- fix org.openqa.selenium.NoSuchWindowException when find element on ie11.
Steps:1.I was able to resolve the issue after adding the site URL under trusted sites of IE. The sam ...
- RMB转换人民币大小金额
MXS&Vincene ─╄OvЁ &0000015 ─╄OvЁ MXS&Vincene MXS&Vincene ─╄OvЁ:今天很残酷,明天更残酷,后天很美好 ...
- 使用node-webkit开发exe窗口程序
首发:个人博客,更新&纠错&回复 ====关于原生程序与壳中程序的议论begin==== 在所有用户windows机器上都能直接跑的程序,如果不采用微软系的语言,如VB,C++,C#等 ...
- WM_SETFOCUS和WM_KILLFOCUS、WM_GETDLGCODE、CM_ENTER...
procedure WMSetFocus (var Message: TWMSetFocus); message WM_SETFOCUS; //获得焦点 procedure WMKillFocus ( ...
- 基于mjpg_streamer视频服务器移植【转】
本文转载自:http://blog.csdn.net/wavemcu/article/details/7539560 MJPG简介: MJPG是MJPEG的缩写,但是MJPEG还可以表示文件格式扩展名 ...
- xhr dojo load
require(["dojo/_base/xhr"], function(xhr) { // Execute a HTTP GET request xhr.get({ // The ...