| 项目搜索 |
| |
|
代码片段库:
查看代码片段
浏览
| 提交新的代码片段
| 创建代码包
生日提醒器
|
类型:
Full Script |
类别:
HTML Manipulation
|
许可证:
GNU General Public License |
语言:
JavaScript
|
描述:
一个生日提醒脚本,可以提醒你最近要过生日的亲友
|
该代码片段的版本系列:
片段ID |
下载版本 |
提交时间 |
提交人 |
删除 |
4729 | 1.0 | 2003-10-14 16:50 | cbd001 | |
点击"下载版本"来下载该代码片段.
最新版本的代码片段: 1.0
脚本说明:
第一步:把如下代码加入<head>区域中
<SCRIPT LANGUAGE="JavaScript">
<!--
function birthday(year,month,date,person) {
this.year=year
this.month=month
this.date=date
this.person=person
}
function birthdaylist() {
}
blist=new birthdaylist()
blist[0]= new birthday(84,1,16,"Matthew")
blist[1]= new birthday(53,1,27,"Brenda")
blist[2]= new birthday(82,3,1,"Ray")
blist[3]= new birthday(88,4,27,"Michael")
blist[4]= new birthday(86,9,2,"Andrew")
blist[5]= new birthday(49,11,24,"Raymond")
var now=new Date()
today=new Date(now.getYear(),now.getMonth(),now.getDate()) // today 0:00:00
function daysFromToday(sdate) {
return Math.round((sdate.getTime()-today.getTime())/(24*60*60*1000))
}
function writeNextBirthday(list) {
var daysToClosest=888
var closest
for (var i in list) {
thisDate=new Date(today.getYear(),list[i].month,list[i].date)
if (daysFromToday(thisDate)<0)
thisDate.setYear(today.getYear()+1)
if (daysFromToday(thisDate)<daysToClosest) {
daysToClosest=daysFromToday(thisDate)
closest=i
}
}
if (daysToClosest==0)
document.write("<B>So today "+list[closest].person+" became "+(today.getYear()-list[closest].year)+" years old !! Hoorah!</B><P>")
else if (daysToClosest==1)
document.write("So tomorrow "+list[closest].person+" will become "+(today.getYear()-list[closest].year)+" !<P>")
else
document.write("So the next birthday will be "+list[closest].person+"'s, in "+daysToClosest+" days.<P>")
}
// end hiding -->
</SCRIPT>
第二步:把如下代码加入<body>区域中
<SCRIPT LANGUAGE="JavaScript">
<!--
writeNextBirthday(blist)
// -->
</SCRIPT>
如果您修改了一个代码片段并且觉得很应该让别人共享,您可以把这作为这个代码片段的最新版本提交上来. |
|