js实现倒计时时钟的示例代码

时间:2024-04-22 22:30:13 

如下所示:


<!--将以下代码加入HTML的<Body></Body>之间-->

<SCRIPT language=JavaScript1.2>
function setcountdown(theyear,themonth,theday){
yr=theyear;mo=themonth;da=theday
}
setcountdown(2008,7,12)
var occasion="2008北京奥运会"
var message_on_occasion="盼望已久的时刻终于来到了!"
var countdownwidth='480px'
var countdownheight='20px'
var countdownbgcolor='tan'
var opentags='<font face="宋体"><small>'
var closetags='</small></font>'
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
var crosscount=''
function start_countdown(){
if (document.layers)
document.countdownnsmain.visibility="show"
else if (document.all||document.getElementById)
crosscount=document.getElementById&&!document.all?document.getElementById("countdownie") : countdownie
countdown()
}

if (document.all||document.getElementById)
document.write('<span id="countdownie" style="width:'+countdownwidth+'; background-color:'+countdownbgcolor+'"></span>')

window.onload=start_countdown


function countdown(){
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
futurestring=montharray[mo-1]+" "+da+", "+yr
dd=Date.parse(futurestring)-Date.parse(todaystring)
dday=Math.floor(dd/(60*60*1000*24)*1)
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
if(dday<=0&&dhour<=0&&dmin<=0&&dsec<=1&&todayd==da){
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+message_on_occasion+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+message_on_occasion+closetags
return
}
else if (dday<=-1){
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+"时间已经过了!"+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+"Occasion already passed! "+closetags
return
}
else{
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds left until "+occasion+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+"还有 "+dday+ " 天, "+dhour+" 小时, "+dmin+" 分, "+dsec+" 秒 就是 "+occasion+closetags
}
setTimeout("countdown()",1000)
}
</SCRIPT>
<SCRIPT type="text/javascript" src=""></SCRIPT>
<SCRIPT language="JavaScript">
<!--
BaiduWriteAD("zouwenyedg","3");
//-->
</SCRIPT>


<ILAYER id=countdownnsmain visibility="hide" bgColor="&{countdownbgcolor};"
height="&{countdownheight};" width="&{countdownwidth};"><LAYER
id=countdownnssub height="&{countdownheight};"
width="&{countdownwidth};" top="0" left="0"></LAYER></ILAYER>

标签:倒计时时钟,js
0
投稿

猜你喜欢

  • python正则表达式之对号入座篇

    2021-03-31 17:59:55
  • python 如何比较两集合的大小关系

    2023-10-14 01:37:06
  • Tensorflow与RNN、双向LSTM等的踩坑记录及解决

    2021-04-29 21:25:55
  • Linux下docker安装mysql8并配置远程连接

    2024-01-18 15:53:43
  • perl比较两个文件字符串的实例代码

    2023-02-15 15:40:18
  • Vue2.0/3.0双向数据绑定的实现原理详解

    2024-05-21 10:17:58
  • Python实现拷贝多个文件到同一目录的方法

    2021-09-03 20:56:25
  • MySQL数据备份方法的选择与思考

    2024-01-19 21:02:50
  • python3简单实现微信爬虫

    2022-10-22 20:55:12
  • Informatica bulk与normal模式的深入详解

    2024-01-16 01:30:28
  • Python格式化输出%s和%d

    2021-05-02 14:13:08
  • 利用python爬取散文网的文章实例教程

    2023-06-17 10:40:18
  • python状态机transitions库详解

    2021-07-14 15:52:16
  • 使用Python编写简单的端口扫描器的实例分享

    2023-07-20 20:18:32
  • Numpy中的mask的使用

    2022-06-10 19:33:11
  • python cv2图像质量压缩的算法示例

    2023-08-16 19:09:02
  • Python中类型关系和继承关系实例详解

    2023-10-08 06:15:06
  • perl产生随机数实现代码

    2023-04-14 05:30:10
  • Django中间件实现拦截器的方法

    2022-10-21 04:47:53
  • 分享几个字体设计

    2007-10-10 13:53:00
  • asp之家 网络编程 m.aspxhome.com