字体:  

一段 JavaScript 代码!!!

skybird 发表于: 2004-11-26 13:05 来源: 工程博客网

<Script Language = "JavaScript">
function time1()
{
now=new Date();
m=now.getMonth();
n=now.getYear()
a=2008-now.getYear();
b=12-now.getMonth();
if(m=1,3,5,7,8,10,12){c=31-now.getDate()}
if(m=4,6,9){c=30-now.getDate()}
if(m=2){c=28-now.getDate()}
if(n=2004,2008){c=29-now.getDate()}
e="0"+24-now.getHours();
f="0"+59-now.getMinutes();
g="0"+60-now.getSeconds();
if(e>10){e=24-now.getHours()}
if(f>10){f=59-now.getMinutes()}
if(g>10){g=60-now.getSeconds()}
document.Time.CLOCK.value="离2008北京奥运会还有"+a+"年"+b+"个月"+c+"天"+e+"小时"+f+"分"+g+"秒"
setTimeout( 'time1()',1000)
}
</SCRIPT>
<form method="post" name="Time">
<input name="CLOCK" size="52" value="">
</form>
<SCRIPT>
time1()
</SCRIPT>

最新回复

斑竹 at 2004-11-27 16:13:06
这种小东西你也发啊?
浪漫化石 at 2004-12-07 22:37:38
怎么了?
我觉得很好啊~有学习价值就好了
ytkxyz at 2004-12-11 17:15:07
你看的懂吗?
NsGFr at 2005-6-08 13:34:38
程序计算日期有误的

e="0"+24-now.getHours();    //这里应该拿23减
f="0"+59-now.getMinutes();  // 这里对了
g="0"+60-now.getSeconds(); // 这里对了

if(n=2004,2008){c=29-now.getDate()}
//这里如果你就按照2008年全年都开奥运的话,这里是没用的;因为我看你的发帖日期是在2004年11月的;多余的。

a=2008-now.getYear()-1;                  // 这里你是不是按照2008年这个整数来算奥运呢? 至2008年年数差 这里是不是应该再减1
b=12-now.getMonth()-1;      

部分修改成这样
e=23-now.getHours();
f=59-now.getMinutes();
g=60-now.getSeconds();
// if(e>10){e=23-now.getHours()}
// if(f>10){f=59-now.getMinutes()}
// if(g>10){g=60-now.getSeconds()}

如果拿这样的程序工作,没过几天老板就生气了。

[ Last edited by NsGFr on 2005-6-8 at 13:35 ]