宝宝成长计时免费代码

已为老胡 2012-06-19 PM 950℃ 0条

程程出生已经一个多月了,刚出生时,小胡还可以按天计时,随着成长,数天数就有些工作量了。以下这段小代码可以替小胡完成计时的工作,如果您有网站或博客空间,不妨给宝宝(或其他人亦可)做一个成长计时模块输出,很贴心的主意哦!

演示就在林林漫记的顶部说明框内:“程程已经1个月零19天啦”,只是很简单的输出计时,还有生日快乐等祝福语。有兴趣的朋友还可以做些CSS美化。

上代码:

<script language="JavaScript" type="text/javascript">
now = new Date()
nowyear=now.getFullYear()
if(nowyear<2000)
nowyear=nowyear+1900
nowmonth=now.getMonth()+1
nowdate=now.getDate()
years=nowyear-2012                //2010改成宝宝生日那年
months=nowmonth-04               //06改成宝宝生日那月
dates=nowdate-26                    //26改成宝宝生日那天
if((years<0)||((years==0)&&(months<0))||((years==0)&&(months==0)&&(dates<=0)))
document.write("<span><font color=red>你的系统时钟好像不太对哦!</font></span>")
else {
if(dates<0) {
months=months-1
dates=dates+30
}
if(months<0) {
years=years-1
months=months+12
}
document.write("<span>程程已经")         //程程改成宝宝名字
if (years>0) {
document.write(years)
document.write("岁")
}
if(months>0) {
document.write(months)
document.write("个月")
}
if(((years>0)||(months>0))&&(dates>0))
document.write("零")
if(dates>0) {
document.write(dates)
document.write("天")
}
else
document.write("整")
document.write("啦</span>")
if((months==0)&&(dates==0)) {
document.write("<span>!<font color=red><b>程生日快乐!") //程程改成宝宝名字
document.write("</b></font></span>")
}
}
</script>

非特殊说明,本博所有文章均为博主原创。

评论啦~