利用中午休息的时间写了一个倒计时,刚刚学的,望大家指教一二,图片在附件中
<html>
<head>
<title>北京奥运会的倒计时</title>
<script language="javascript">
<!--
c0=new Image(); c0.src="img/c0.gif"; //加载数字图片
c1=new Image(); c1.src="img/c1.gif";
c2=new Image(); c2.src="img/c2.gif";
c3=new Image(); c3.src="img/c3.gif";
c4=new Image(); c4.src="img/c4.gif";
c5=new Image(); c5.src="img/c5.gif";
c6=new Image(); c6.src="img/c6.gif";
c7=new Image(); c7.src="img/c7.gif";
c8=new Image(); c8.src="img/c8.gif";
c9=new Image(); c9.src="img/c9.gif";
function DownTime()
{
BJDate=new Date(2008,7,8,20,0);//北京奥运会,2008/8/8/20/00
NowDate=new Date(); //取现在的时间
Inter=BJDate.getTime()-NowDate.getTime();
if(Inter<0)
{
hlb.innerHTML="北京奥运会已经开始了";
return;
}
days=Math.floor(Inter/(24*60*60*1000));
document.images.a.src=eval("c"+Math.floor(days/100)+".src");
document.images.b.src=eval("c"+Math.floor(days/10%10)+".src");
document.images.c.src=eval("c"+Math.floor(days%10)+".src");
temp=Inter%(24*60*60*1000);
hours=Math.floor(temp/(60*60*1000));
hours=less10(hours);
document.images.d.src=eval("c"+Math.floor(hours/10)+".src");
document.images.e.src=eval("c"+Math.floor(hours%10)+".src");
temp=temp%(60*60*1000);
minutes=Math.floor(temp/(60*1000));
minutes=less10(minutes);
document.images.f.src=eval("c"+Math.floor(minutes/10)+".src");
document.images.g.src=eval("c"+Math.floor(minutes%10)+".src");
temp=temp%(60*1000);
seconds=Math.floor(temp/1000);
seconds=less10(seconds);
document.images.h.src=eval("c"+Math.floor(seconds/10)+".src");
document.images.i.src=eval("c"+Math.floor(seconds%10)+".src");
setTimeout("DownTime()",1000);
}
function less10(num)
{
if(num<10) num="0"+num;
return num;
}
//-->
</script>
<body onload="DownTime()">
<span style="color:red">现在离北京奥运会还有: </span>
<img src="img/cb.gif" name="a"><img src="img/cb.gif" name="b"><img src="img/cb.gif" name="c"> 天
<img src="img/cb.gif" name="d"><img src="img/cb.gif" name="e"> 小时
<img src="img/cb.gif" name="f"><img src="img/cb.gif" name="g"> 分钟
<img src="img/cb.gif" name="h"><img src="img/cb.gif" name="i"> 秒
</body>
</html>
http://www.phpfine.com/aoyun.htm 范例演示
[此贴子已经被作者于2007-8-23 21:40:23编辑过]