本文目录一览:
高分跪求求一个循环倒计时的JS代码,网页上用的。
span id="span_dt_dt"/span
script language=javascript
var daytemp=3//新增加变量
function show_date_time(){
window.setTimeout("show_date_time()", 1000);
BirthDay=new Date("02/26/2012");//改成你的计时日期
today=new Date();
timeold=(BirthDay.getTime()-today.getTime());
sectimeold=timeold/1000
secondsold=Math.floor(sectimeold);
msPerDay=24*60*60*1000
e_daysold=timeold/msPerDay
daysold=Math.floor(e_daysold);
e_hrsold=(e_daysold-daysold)*24;
hrsold=Math.floor(e_hrsold);
if (hrsold 10){
hrsold = "0"+hrsold;
}
e_minsold=(e_hrsold-hrsold)*60;
minsold=Math.floor((e_hrsold-hrsold)*60);
if (minsold 10){
minsold = "0"+minsold;
}
seconds=Math.floor((e_minsold-minsold)*60);
if (seconds 10){
seconds = "0"+seconds;
}
//以下为增加代码:希望你测试通过,然后给分
if(daysold=0)
{
document.getElementById("span_dt_dt").innerHTML=daysold+"bD/b"+hrsold+"bH/b"+minsold+"bM/b"+seconds+"bS/b";
}
else
{
if(daysold+daytemp=0)
{
document.getElementById("span_dt_dt").innerHTML=(daysold+daytemp)+"bD/b"+hrsold+"bH/b"+minsold+"bM/b"+seconds+"bS/b";
}
else
{
daytemp=daytemp+3;
}
}
}
show_date_time();
/script
JS倒计时页面代码(要求读取服务器时间)
script language="JavaScript"
function setTab(name,cursel,n){
for(i=1;i=n;i++){
var menu=document.getElementById(name+i);
var con=document.getElementById("con_"+name+"_"+i);
menu.className=i==cursel?"hover":"";
con.style.display=i==cursel?"block":"none";
}
}var DifferenceHour = -1
var DifferenceMinute = -1
var DifferenceSecond = -1
var Tday = new Date("Feb 14, 2010 00:00:00") //**倒计时时间点-注意格式
var daysms = 24 * 60 * 60 * 1000
var hoursms = 60 * 60 * 1000
var Secondms = 60 * 1000
var microsecond = 1000function left(mainStr,lngLen) {
if (lngLen0) {return mainStr.substring(0,lngLen)}
else{return null}
}
function right(mainStr,lngLen) { if (mainStr.length-lngLen=0 mainStr.length=0 mainStr.length-lngLen=mainStr.length) {
return mainStr.substring(mainStr.length-lngLen,mainStr.length)}
else{return null}
}
function mid(mainStr,starnum,endnum){
if (mainStr.length=0){
return mainStr.substr(starnum,endnum)
}else{return null} }function clock()
{
var time = new Date()
var hour = time.getHours()
var minute = time.getMinutes()
var second = time.getSeconds()
var timevalue = ""+((hour 12) ? hour-12:hour)
timevalue +=((minute 10) ? ":0":":")+minute
timevalue +=((second 10) ? ":0":":")+second
timevalue +=((hour 12 ) ? " PM":" AM")var convertHour = DifferenceHour
var convertMinute = DifferenceMinute
var convertSecond = DifferenceSecond
var Diffms = Tday.getTime() - time.getTime()
DifferenceHour = Math.floor(Diffms / daysms)
Diffms -= DifferenceHour * daysms
DifferenceMinute = Math.floor(Diffms / hoursms)
Diffms -= DifferenceMinute * hoursms
DifferenceSecond = Math.floor(Diffms / Secondms)
Diffms -= DifferenceSecond * Secondms
var dSecs = Math.floor(Diffms / microsecond)var dd=document.getElementById("dd");
var hh=document.getElementById("hh");
var mm=document.getElementById("mm");
var ss=document.getElementById("ss");ddstr = DifferenceHour.toString();
hhstr = DifferenceMinute.toString();
mmstr = DifferenceSecond.toString();
ssstr = dSecs.toString();if (Tday.getTime() time.getTime()){
if (ddstr.length2){
ddstrs = "span class='num0'/spanspan class='num"+ddstr.substr(0,1)+"'/span";
}else{
ddstrs = "span class='num"+ddstr.substr(0,1)+"'/spanspan class='num"+ddstr.substr(1,2)+"'/span";
}if (hhstr.length2){
hhstrs = "span class='num0'/spanspan class='num"+hhstr.substr(0,1)+"'/span";
}else{
hhstrs = "span class='num"+hhstr.substr(0,1)+"'/spanspan class='num"+hhstr.substr(1,2)+"'/span";
}if (mmstr.length2){
mmstrs = "span class='num0'/spanspan class='num"+mmstr.substr(0,1)+"'/span";
}else{
mmstrs = "span class='num"+mmstr.substr(0,1)+"'/spanspan class='num"+mmstr.substr(1,2)+"'/span";
}if (ssstr.length2){
ssstrs = "span class='num0'/spanspan class='num"+mmstr.substr(0,1)+"'/span";
}else{
ssstrs = "span class='num"+ssstr.substr(0,1)+"'/spanspan class='num"+ssstr.substr(1,2)+"'/span";
}
}else{
ddstrs="span class='num0'/spanspan class='num0'/span"
hhstrs="span class='num0'/spanspan class='num0'/span"
mmstrs="span class='num0'/spanspan class='num0'/span"
ssstrs="span class='num0'/spanspan class='num0'/span"
}if(convertHour != DifferenceHour) dd.innerHTML=ddstrs;
if(convertMinute != DifferenceMinute) hh.innerHTML=hhstrs;
if(convertSecond != DifferenceSecond) mm.innerHTML=mmstrs;
ss.innerHTML=ssstrs;
setTimeout("clock()",1000)}/script 上面的是JS部分的。 下面是HTML部分的。div class="mains"
div class="djs"
div id="dd"/div
div id="tsfm"天/div
div id="hh"/div
div id="tsfm"时/div
div id="mm"/div
div id="tsfm"分/div
div id="ss"/div
div id="tsfm"秒/div
/div 我上面的JS部分的数字全部是用的图片格式显示倒计时数字的哈,你也可以自己改成数字。 好了,上面的代码全部是我之前给客户写的一个春节倒计时贺卡的程序页面,纯原创,并且一直在用,所以是没有任何问题的,你自己应该懂一些技术吧,所以上面的代码你应该看的懂,很简单的。 就不要再追问了,自己多下下功夫研究下,因为最近比较忙,不见得有时间回复,见谅。记得给我分哈,要升级这个号的级别,以后好推广用,谢谢了。
javascript倒计时代码
我给你做了一个,你看行不行?
js代码:fun.js
var timmerID = null;
function time() {
var time = document.getElementById("now");
var left = document.getElementById("left");
var t = time.value.split(":");
var hour = parseInt(t[0]);
var min = parseInt(t[1]);
min=min+1;
if(min==60){
hour=hour+1;
min=0;
if(hour==24){
hour=0;
}
}
time.value=hour+":"+min;
left.value = left.value-1;
if(left.value==0){
mystop();
alert("时间已到!");
}
}
function mystart() {
var left = document.getElementById("left");
left.value="40";
timmerID = window.setInterval("time()", 1000*60);
}
function mystop() {
window.clearInterval(timmerID);
}
html页面:
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
html
head
titletime.html/title
script type="text/javascript" src="fun.js"/script
/head
body
时间起点:input type="text" name="now" id="now" value="0:0"/input type="button" value="开始" onclick="mystart();"br
剩余时间:input type="text" name="left" id="left" value="40" disabled="disabled"/分钟br
/body
/html
补充:这个javascript放在一个文件叫fun.js,在html页面中要引用此文件,如:script type="text/javascript" src="fun.js"/script ,注意不要把路径弄错了,src后面的路径按照实际的来,如果两个文件在一个目录下,就是如上这样引用,当然也可以直接把全部的js内容放在html文件的头部,如:script type="text/javascript"
!--javascript代码--
/script
JS 倒计时实现代码(时、分,秒)
JS实现倒计时(时、分,秒)
var
interval
=
1000;
function
ShowCountDown(year,month,day,divname)
{
var
now
=
new
Date();
var
endDate
=
new
Date(year,
month-1,
day);
var
leftTime=endDate.getTime()-now.getTime();
var
leftsecond
=
parseInt(leftTime/1000);
//var
day1=parseInt(leftsecond/(24*60*60*6));
var
day1=Math.floor(leftsecond/(60*60*24));
var
hour=Math.floor((leftsecond-day1*24*60*60)/3600);
var
minute=Math.floor((leftsecond-day1*24*60*60-hour*3600)/60);
var
second=Math.floor(leftsecond-day1*24*60*60-hour*3600-minute*60);
var
cc
=
document.getElementById(divname);
cc.innerHTML
=
"脚本之家提示距离"+year+"年"+month+"月"+day+"日还有:"+day1+"天"+hour+"小时"+minute+"分"+second+"秒";
}
window.setInterval(function(){ShowCountDown(2010,4,20,'divdown1');},
interval);
[Ctrl+A
全选
注:如需引入外部Js需刷新才能执行]