您的位置:

关于javascript春节倒计时的信息

本文目录一览:

还是关于JavaScript中倒计时的问题

剩余时间保存在cookie里面就可以:

一、页面显示剩余时间的时候,先检查cookie里面是否有值,为空才从3599开始,否则使用cookie的数值;

二、每次剩余时间更新时候,同时修改cookie数值

初学javascript,要求编写一个倒计时,格式如00:00:00该怎么实现?时间是自己设定,想设置多少秒就多少秒

我也是业余爱好者, 以下试编写脚本如下:

html

head

title倒计时测试/title

script language="JavaScript"

var DifferenceHour = -1;

var DifferenceMinute = -1;

var DifferenceSecond = -1;

var Tday = new Date(2012,2,10,22,0,0,0); //倒计时时间点-年,月,日,时,分,秒,毫秒

var DAY_MS = 24 * 60 * 60 * 1000;

var HOUR_MS = 60 * 60 * 1000;

var SECOND_MS = 60 * 1000;

var MS = 1000;

function formatstr(value)

{

return (value9)?"0"+value:value;

}

function clock()

{

var time = new Date();

if(Tday.getTime()time.getTime())

{

alert("当前倒计时已终止!");

return;

};

var nowtime = time.toLocaleString();

var totime = Tday.toLocaleString();

var Diffms = Tday.getTime() - time.getTime(); //毫秒差

DifferenceHour = Math.floor(Diffms / DAY_MS); //转换成小时

Diffms -= DifferenceHour * DAY_MS;

DifferenceMinute = Math.floor(Diffms / HOUR_MS); //转换成分钟

Diffms -= DifferenceMinute * HOUR_MS;

DifferenceSecond = Math.floor(Diffms / SECOND_MS); //转换成秒

Diffms -= DifferenceSecond * SECOND_MS;

var dSecs = Math.floor(Diffms / MS); //转换成毫秒

var havetime = formatstr(DifferenceMinute)+" : "+formatstr(DifferenceSecond)+" : "+formatstr(dSecs);

document.formnow.totime.value = totime;

document.formnow.nowtime.value = nowtime;

document.formnow.havetime.value = havetime;

setTimeout("clock()",1000);

}

/script

/head

!--BODY里面的ONLOAD注意--

body onload="clock();return true" text="red"

!--实现显示--

form name="formnow"

!--input name="dd" type="text" style="border:0;" size=2

天--

设定时间:

input name="totime" type="text" style="border:0;" size=25 /

br /

当前时间:

input name="nowtime" type="text" style="border:0;" size=25 /

br /br /

倒计时时间:

input name="havetime" type="text" style="border:0;" size=25 /

br /

/form

求JS倒计时程序(高分)

倒计时生成器JS脚本

说明: 用来生成倒计时JS代码的脚本

效果: 点这里在新窗口中看效果!

代码: 要完成此效果需要两个步骤

第一步:把如下代码加入到head区域中

SCRIPT language=javascript

!--

function generate(form){

for(var q=0;q12;q++){

if(document.me.m.options[document.me.m.selectedIndex].value==q){

var m2=q+1

}

var txt='!-- 要完成此效果需要三个步骤:\r\n\r\n'

+' 1. 将第一部分粘贴到HTML的HEAD区\r\n'

+' 2. 将OnLoad事件加入BODY标签内\r\n'

+' 3. 将最后一部分代码加入BODY区 --\r\n\r\n'

+'!-- 第一步: 将如下代码加入到HEAD区域中--\r\n\r\n'

+'HEAD\r\n\r\nSCRIPT LANGUAGE="JavaScript"\r\n\r\n'

+'!-- Begin\r\n'

+'var Temp2;\n'

+'var timerID = null;\n'

+'var timerRunning = false;\n'

+'function arry() {\n'

+'this.length = 12;\n'

+'this[0] = 31;\n'

+'this[1] = 28;\n'

+'this[2] = 31;\n'

+'this[3] = 30;\n'

+'this[4] = 31;\n'

+'this[5] = 30;\n'

+'this[6] = 31;\n'

+'this[7] = 31;\n'

+'this[8] = 30;\n'

+'this[9] = 31;\n'

+'this[10] = 30;\n'

+'this[11] = 31;\n'

+'}\n'

+'var date = new arry();\n'

+'\n'

+'function stopclock() {\n'

+'if(timerRunning)\n'

+'clearTimeout(timerID);\n'

+'timerRunning = false;\n'

+'}\n'

+'\n'

+'function startclock() {\n'

+'stopclock();\n'

+'showtime();\n'

+'}\n'

+'\n'

+'function showtime() {\n'

+'now = new Date();\n'

+'var CurMonth = now.getMonth();\n'

+'var CurDate = now.getDate();\n'

+'var CurYear = now.getFullYear();\n'

+'now = null;\n'

+'if ('+document.me.d.options[document.me.d.selectedIndex].value+'CurDate) {\n'

+'CurDate -= date[CurMonth]; CurMonth++;\n'

+'}\n'

+'if ('+document.me.m.options[document.me.m.selectedIndex].value+' CurMonth) {\n'

+'CurMonth -= 12; CurYear++;\n'

+'}\n'

+'\n'

+'var Yearleft = '

+document.me.y.options[document.me.y.selectedIndex].value+' - CurYear;\n'

+'var Monthleft = '

+document.me.m.options[document.me.m.selectedIndex].value+' - CurMonth;\n'

+'var Dateleft = '

+document.me.d.options[document.me.d.selectedIndex].value+' - CurDate;\n'

+'\n'

+'document.dateform.a.value = Yearleft;\n'

+'document.dateform.b.value = Monthleft;\n'

+'document.dateform.c.value = Dateleft;\n'

+'\n'

+'timerID = setTimeout("showtime()",1000);\n'

+'timerRunning = true;\n'

+'}\n'

+'/\/ End --\r\n\/script\r\n'

+'\/H'+'EAD\r\n\r\n'

+'!-- 第二步:把OnLoad事件加在BODY标记里 --\r\n\r\n'

+'BO'+'DY Onload="startclock()"\r\n\r\n'

+'!-- 第三步:把如下代码加入到BODY区域中 --\r\n\r\n'

+'form name=dateform距离'

+m2+'/'+document.me.d.options[document.me.d.selectedIndex].value+'/'

+document.me.y.options[document.me.y.selectedIndex].value

+'还有\n'

+'input type=text name=a size=2 value=""年\n'

+'input type=text name=b size=2 value=""月\n'

+'input type=text name=c size=2 value=""天\n'

+'/fo'+'rm\r\n\r\n'

+''+'!-- 代码长度: 1.95 KB --'+''

;}document.mail.source.value=txt;document.mail.source2.value=txt;}

//--

/SCRIPT

第二步:把如下代码加入到body区域中

div align="center"

table border=5 bordercolor=#000000 borderlight=green

tr

td align=centerfont size="4" color="#CCCC00" face="楷体_GB2312"

倒计时JS代码生成器/font

/td

/tr

tr

td align=center

form name=me

p

select name=m size=1

option value=0January /option

option value=1February /option

option value=2March /option

option value=3April /option

option value=4May /option

option value=5June /option

option value=6July /option

option value=7August /option

option value=8September /option

option value=9October /option

option value=10November /option

option value=11December /option

/select

select name=d size=1

option value=11 /option

option value=22 /option

option value=33 /option

option value=44 /option

option value=55 /option

option value=66 /option

option value=77 /option

option value=88 /option

option value=99 /option

option value=1010 /option

option value=1111 /option

option value=1212 /option

option value=1313 /option

option value=1414 /option

option value=1515 /option

option value=1616 /option

option value=1717 /option

option value=1818 /option

option value=1919 /option

option value=2020 /option

option value=2121 /option

option value=2222 /option

option value=2323 /option

option value=2424 /option

option value=2525 /option

option value=2626 /option

option value=2727 /option

option value=2828 /option

option value=2929 /option

option value=3030 /option

option value=3131 /option

/select

select name=y size=1

option value=19991999 /option

option value=20002000 /option

option value=20012001 /option

option value=20022002 /option

option value=20032003 /option

option value=20042004 /option

option value=20052005 /option

option value=20062006 /option

option value=20072007 /option

option value=20082008 /option

option value=20092009 /option

/selectbr

input type=button onclick=generate() value=生成代码 class=yk9

p/p

/form

form name=mail

input type=hidden name=scriptname value="Countdown Creator"

input type=hidden name=source2 value

table bgcolor=dedfdf border=1 cellpadding=1 width=396

tr

td align=center height=218

textarea name=source rows=12 cols=55 class=yk9

/textarea

brbr/td

td/td

/tr

/table

/form

/td

/tr

/table

/div

参考资料:

谁能给我一个倒计时的代码啊?

第一种:精确到秒的javascript倒计时代码

HTML代码:

form name="form1"

div align="center" align="center"

center离2010年还有:br

input type="textarea" name="left" size="35" style="text-align: center"

/center

/div

/form

script LANGUAGE="javascript"

startclock()

var timerID = null;

var timerRunning = false;

function showtime() {

Today = new Date();

var NowHour = Today.getHours();

var NowMinute = Today.getMinutes();

var NowMonth = Today.getMonth();

var NowDate = Today.getDate();

var NowYear = Today.getYear();

var NowSecond = Today.getSeconds();

if (NowYear 2000)

NowYear=1900+NowYear;

Today = null;

Hourleft = 23 - NowHour

Minuteleft = 59 - NowMinute

Secondleft = 59 - NowSecond

Yearleft = 2009 - NowYear

Monthleft = 12 - NowMonth - 1

Dateleft = 31 - NowDate

if (Secondleft0)

{

Secondleft=60+Secondleft;

Minuteleft=Minuteleft-1;

}

if (Minuteleft0)

{

Minuteleft=60+Minuteleft;

Hourleft=Hourleft-1;

}

if (Hourleft0)

{

Hourleft=24+Hourleft;

Dateleft=Dateleft-1;

}

if (Dateleft0)

{

Dateleft=31+Dateleft;

Monthleft=Monthleft-1;

}

if (Monthleft0)

{

Monthleft=12+Monthleft;

Yearleft=Yearleft-1;

}

Temp=Yearleft+'年, '+Monthleft+'月, '+Dateleft+'天, '+Hourleft+'小时, '+Minuteleft+'分, '+Secondleft+'秒'

document.form1.left.value=Temp;

timerID = setTimeout("showtime()",1000);

timerRunning = true;

}

var timerID = null;

var timerRunning = false;

function stopclock () {

if(timerRunning)

clearTimeout(timerID);

timerRunning = false;

}

function startclock () {

stopclock();

showtime();

}

// --

/script

第二种:某某运动会

HTML代码:

!--倒计时Javascript begin--

script language="JavaScript"

!--

function DigitalTime1()

{

var deadline= new Date("08/13/2007") //开幕倒计时

var symbol="8月13日"

var now = new Date()

var diff = -480 - now.getTimezoneOffset() //是北京时间和当地时间的时间差

var leave = (deadline.getTime() - now.getTime()) + diff*60000

var day = Math.floor(leave / (1000 * 60 * 60 * 24))

var hour = Math.floor(leave / (1000*3600)) - (day * 24)

var minute = Math.floor(leave / (1000*60)) - (day * 24 *60) - (hour * 60)

var second = Math.floor(leave / (1000)) - (day * 24 *60*60) - (hour * 60 * 60) - (minute*60)

var deadline_2= new Date("08/13/2004") //开幕后计时

var symbol_2="8月13日"

var now_2 = new Date()

var diff_2 = -480 - now.getTimezoneOffset() //是北京时间和当地时间的时间差

var leave_2 = (now_2.getTime() - deadline_2.getTime()) + diff_2*60000

var day_2 = Math.floor(leave_2 / (1000 * 60 * 60 * 24))

var hour_2 = Math.floor(leave_2 / (1000*3600)) - (day_2 * 24)

var minute_2 = Math.floor(leave_2 / (1000*60)) - (day_2 * 24 *60) - (hour_2 * 60)

var second_2 = Math.floor(leave_2 / (1000)) - (day_2 * 24 *60*60) - (hour_2 * 60 * 60) - (minute_2*60)

day=day+1;

day_2=day_2+1;

if (day0) //还未开幕

{

//LiveClock1.innerHTML = "现在"+symbol+"天"

LiveClock1.innerHTML = "font

setTimeout("DigitalTime1()",1000)

}

if (day0) //已经开幕

{

//LiveClock1.innerHTML = "现在离"+symbol+"还有"+day+"天"+hour+"小时"+minute+"分"+second +"秒"

LiveClock1.innerHTML = "font

setTimeout("DigitalTime1()",1000)

}

if (day==0) //正在开幕

{

//LiveClock1.innerHTML = "现在"+symbol+"天"

LiveClock1.innerHTML = "font

setTimeout("DigitalTime1()",1000)

}

if (day0 day_219) //某某运动会结束

{

//LiveClock1.innerHTML = "现在离"+symbol+"还有"+day+"天"+hour+"小时"+minute+"分"+second +"秒"

LiveClock1.innerHTML = "font

setTimeout("DigitalTime1()",1000)

}

}

// --

/script

!--倒计时Javascript end--

body onload=DigitalTime1()

div id= LiveClock1/div

/body 第三种:小时倒计时

HTML代码:

SCRIPT LANGUAGE="JavaScript"

!--

var maxtime = 60*60 //一个小时,按秒计算,自己调整!

function CountDown(){

if(maxtime=0){

minutes = Math.floor(maxtime/60);

seconds = Math.floor(maxtime%60);

msg = "距离结束还有"+minutes+"分"+seconds+"秒";

document.all["timer"].innerHTML=msg;

if(maxtime == 5*60) alert('注意,还有5分钟!');

--maxtime;

}

else{

clearInterval(timer);

alert("时间到,结束!");

}

}

timer = setInterval("CountDown()",1000);

//--

/SCRIPT

div id="timer" style="color:red"/div

第四种:最简倒计时

HTML代码:

Script Language="JavaScript"

!-- Begin

var timedate= new Date("January 14,2006");

var times="研究生考试";

var now = new Date();

var date = timedate.getTime() - now.getTime();

var time = Math.floor(date / (1000 * 60 * 60 * 24));

if (time = 0) ;

document.write("lifont color=#DEDBDE现在离2006年"+times+"还有: font color=#ffffffb"+time +"/b/font 天/font/li");

// End --

/Script

第五种:最简倒计时二

HTML代码:

script language="JavaScript" type="text/javascript"

function djs(){

var urodz= new Date("11/12/2008"); 

var now = new Date();

var num

var ile = urodz.getTime() - now.getTime();

var dni = Math.floor(ile / (1000 * 60 * 60 * 24));

if (dni 1)

num=dni+1

else if (dni == 1) num=2 

else if (dni == 0) num=1

else num=0 

document.write(num)

}

/script

距某某开幕式还有 [script language="JavaScript" type="text/javascript"djs()/script] 天

第五个:Javascript倒计时器 - 采用系统时间自校验

这次利用系统时间自校验倒计时, 无需手工调校使得倒计时更为精确, 代码及详细注释如下:

span id="clock"00:01:11:00/span

input id="startB" type="button" value="start countdown!" onclick="run()"

input id="endB" type="button" value="stop countdown!" onclick="stop()"

br

input id="diff" type="text"

input id="next" type="text"

script language="Javascript"

/* This notice must be untouched at all times.

countdown.js v. 1.0

The latest version is available at

Copyright (c) 2004 Xinyi.Chen. All rights reserved.

Created 7/30/2004 by Xinyi.Chen.

Web:

E-Mail: chenxinyi1978@hotmail.com

Last modified: 7/30/2004

This program is free software;

you can redistribute it and/or modify it under the terms of the

GNU General Public License as published by the Free Software Foundation;

See the GNU General Public License

at for more details.

*/

var normalelapse = 100;

var nextelapse = normalelapse;

var counter;

var startTime;

var start = clock.innerText;

var finish = "00:00:00:00";

var timer = null;

// 开始运行

function run() {

startB.disabled = true;

endB.disabled = false;

counter = 0;

// 初始化开始时间

startTime = new Date().valueOf();

// nextelapse是定时时间, 初始时为100毫秒

// 注意setInterval函数: 时间逝去nextelapse(毫秒)后, onTimer才开始执行

timer = window.setInterval("onTimer()", nextelapse);

}

// 停止运行

function stop() {

startB.disabled = false;

endB.disabled = true;

window.clearTimeout(timer);

}

window.onload = function() {

endB.disabled = true;

}

// 倒计时函数

function onTimer()

{

if (start == finish)

{

window.clearInterval(timer);

alert("time is up!");

return;

}

var hms = new String(start).split(":");

var ms = new Number(hms[3]);

var s = new Number(hms[2]);

var m = new Number(hms[1]);

var h = new Number(hms[0]);

ms -= 10;

if (ms 0)

{

ms = 90;

s -= 1;

if (s 0)

{

s = 59;

m -= 1;

}

if (m 0)

{

m = 59;

h -= 1;

}

}

var ms = ms 10 ? ("0" + ms) : ms;

var ss = s 10 ? ("0" + s) : s;

var sm = m 10 ? ("0" + m) : m;

var sh = h 10 ? ("0" + h) : h;

start = sh + ":" + sm + ":" + ss + ":" + ms;

clock.innerText = start;

// 清除上一次的定时器

window.clearInterval(timer);

// 自校验系统时间得到时间差, 并由此得到下次所启动的新定时器的时间nextelapse

counter++;

var counterSecs = counter * 100;

var elapseSecs = new Date().valueOf() - startTime;

var diffSecs = counterSecs - elapseSecs;

nextelapse = normalelapse + diffSecs;

diff.value = counterSecs + "-" + elapseSecs + "=" + diffSecs;

next.value = "nextelapse = " + nextelapse;

if (nextelapse 0) nextelapse = 0;

// 启动新的定时器

timer = window.setInterval("onTimer()", nextelapse);

}

/script

怎样用javascript写倒计时

form name="form1" action="" 

div align="center" align="middle" 

center离2010年还有:br 

input type="textarea" name="left" size="35" style="text-align: center" mce_style="text-align: center" 

/center 

/div 

/form 

mce:script LANGUAGE="javascript"!-- 

startclock() 

var timerID = null; 

var timerRunning = false; 

function showtime() { 

Today = new Date(); 

var NowHour = Today.getHours(); 

var NowMinute = Today.getMinutes(); 

var NowMonth = Today.getMonth(); 

var NowDate = Today.getDate(); 

var NowYear = Today.getYear(); 

var NowSecond = Today.getSeconds(); 

if (NowYear 2000) 

NowYear=1900+NowYear; 

Today = null; 

Hourleft = 23 - NowHour 

Minuteleft = 59 - NowMinute 

Secondleft = 59 - NowSecond 

Yearleft = 2009 - NowYear 

Monthleft = 12 - NowMonth - 1 

Dateleft = 31 - NowDate 

if (Secondleft0) 

Secondleft=60+Secondleft; 

Minuteleft=Minuteleft-1; 

if (Minuteleft0) 

Minuteleft=60+Minuteleft; 

Hourleft=Hourleft-1; 

if (Hourleft0) 

Hourleft=24+Hourleft; 

Dateleft=Dateleft-1; 

if (Dateleft0) 

Dateleft=31+Dateleft; 

Monthleft=Monthleft-1; 

if (Monthleft0) 

Monthleft=12+Monthleft; 

Yearleft=Yearleft-1; 

Temp=Yearleft+'年, '+Monthleft+'月, '+Dateleft+'天, '+Hourleft+'小时, '+Minuteleft+'分, '+Secondleft+'秒' 

document.form1.left.value=Temp; 

timerID = setTimeout("showtime()",1000); 

timerRunning = true; 

var timerID = null; 

var timerRunning = false; 

function stopclock () { 

if(timerRunning) 

clearTimeout(timerID); 

timerRunning = false; 

function startclock () { 

stopclock(); 

showtime(); 

// --/mce:script 

别地方复制的,测试有效

你把里面的时间数据改成你想要的结果就可以了

关于javascript春节倒计时的信息

2022-11-17
关于java学习笔记良葛格的信息

2022-11-11
关于已前的学习笔记java的信息

2022-11-18
关于java基础知识笔记1的信息

2022-11-20
js基于服务器时间的倒计时功能(js如何实现倒计时秒)

本文目录一览: 1、JS倒计时页面代码(要求读取服务器时间) 2、JS 倒计时实现代码(时、分,秒) 3、求一个倒计时js代码,非常简单的 JS倒计时页面代码(要求读取服务器时间) script la

2023-12-08
关于python学习第四次笔记的信息

2022-11-08
关于chinajsszwyb的信息

本文目录一览: 1、给些广州市的报刊和杂志的网上投稿地址,不要广州日报和羊城晚报给些其他的有稿费 2、中国有多少个航空公司?有人知道吗?分别是哪些? 3、中国航空公司 代码 4、中国有几大航空公司?

2023-12-08
js倒计时器程序(js倒数计时器)

本文目录一览: 1、JS倒计时页面代码(要求读取服务器时间) 2、js写在线考试倒计时器 3、求倒计时代码,js,php都行。格式: 距高考还有 145 天 4、如何实现js优惠券倒计时 5、JS/J

2023-12-08
关于java性能的小笔记(java代码性能分析)

2022-11-12
关于python学习笔记十三的信息

2022-11-19
关于cjstv20171124的信息

本文目录一览: 1、康熙字典22画的字有哪些? 康熙字典22画的字有哪些? 镔、 镲 、躔 、冁、 摛 、蹰 、撺。一、镲拼音chǎ部首钅部部外笔画14画总笔画19画五笔QPWI仓颉OPJBF郑码PW

2023-12-08
java日期类学习笔记(java的时间日期类型)

2022-11-10
java倒计时,java倒计时器

2022-11-30
一个页面多个倒计时js代码(一个页面多个倒计时js代码是什么

本文目录一览: 1、高分跪求求一个循环倒计时的JS代码,网页上用的。 2、JS倒计时页面代码(要求读取服务器时间) 3、javascript倒计时代码 4、JS 倒计时实现代码(时、分,秒) 高分跪求

2023-12-08
java倒计时,java倒计时线程

2022-11-30
web怎么实现倒计时,web倒计时代码

2022-11-23
关于java获取eth余额的信息

2022-11-18
使用JavaScript编写简单的倒计时程序

2023-05-20
jsp程序开发学习笔记2,jsp程序设计题库

本文目录一览: 1、《JSP&Servlet学习笔记》pdf下载在线阅读,求百度网盘云资源 2、林信良编著jsp&servlet学习笔记第2版课后答案吗 3、jsp有没有快速掌握的办法呀? 4、要学J

2023-12-08
关于python学习笔记第十四周的信息

2022-11-15