生日提醒

 做完班级网站之后,觉得有必要把过程中一些可以分享的东西写上来。首先是同学们倍感温馨的生日提示,下面的代码是经过我修改后的,具体效果请看理化检验的班级网站http://ch.sysu.edu.cn/hope/sites/2008yh/。关于生日提醒的代码在网上有不少,大家可以找找看。

    生日提醒的功能由JS实现。

    在js里放上如下代码:

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(年,月,日,"姓名1")
blist[1]= new birthday(1989,5,15,"姓名2")
\*自己增加*\

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 name1="",name2="",name3="",name4="",name5="",name6="",name7="",n=0
for (var i in list) {
thisDate=new Date(today.getYear(),list[i].month-1,list[i].date)
if (daysFromToday(thisDate)<0)
thisDate.setYear(today.getYear()+1)
if (daysFromToday(thisDate)==0)
{n=n+1
document.write("<font color=##000000 style='font-size:11pt;font-family: 宋体;line-height:1.5'> ",
"<img src='Images/bir_0.jpg'> 今天是"+list[i].person+"的生日!<P>")}
}

for (var i in list) {
thisDate=new Date(today.getYear(),list[i].month-1,list[i].date)
if (daysFromToday(thisDate)<0)
thisDate.setYear(today.getYear()+1)
if (daysFromToday(thisDate)==1&&n<4)
{n=n+1
document.write("<font color=##000000 style='font-size:11pt;font-family: 宋体;line-height:1.5'> ","<img src='Images/bir_1.jpg'> "+list[i].person+",将于明天生日<P>")}

}

for (var i in list) {
thisDate=new Date(today.getYear(),list[i].month-1,list[i].date)
if (daysFromToday(thisDate)<0)
thisDate.setYear(today.getYear()+1)
if (daysFromToday(thisDate)==2&&n<4)
{n=n+1
document.write("<font color=##000000 style='font-size:11pt;font-family: 宋体;line-height:1.5'> ","<img src='Images/bir_2.jpg'> "+list[i].person+",将于"+daysFromToday(thisDate)+"天后生日<P>")}
}

for (var i in list) {
thisDate=new Date(today.getYear(),list[i].month-1,list[i].date)
if (daysFromToday(thisDate)<0)
thisDate.setYear(today.getYear()+1)
if (daysFromToday(thisDate)==3&&n<4)
{n=n+1
document.write("<font color=##000000 style='font-size:11pt;font-family: 宋体;line-height:1.5'> ","<img src='Images/bir_2.jpg'> "+list[i].person+",将于"+daysFromToday(thisDate)+"天后生日<P>")}
}

for (var i in list) {
thisDate=new Date(today.getYear(),list[i].month-1,list[i].date)
if (daysFromToday(thisDate)<0)
thisDate.setYear(today.getYear()+1)
if (daysFromToday(thisDate)==4&&n<4)
{n=n+1
document.write("<font color=##000000 style='font-size:11pt;font-family: 宋体;line-height:1.5'> ","<img src='Images/bir_2.jpg'> "+list[i].person+",将于"+daysFromToday(thisDate)+"天后生日。<P>")}
}

for (var i in list) {
thisDate=new Date(today.getYear(),list[i].month-1,list[i].date)
if (daysFromToday(thisDate)<0)
thisDate.setYear(today.getYear()+1)
if (daysFromToday(thisDate)==5&&n<4)
{n=n+1
document.write("<font color=##000000 style='font-size:11pt;font-family: 宋体;line-height:1.5'> ","<img src='Images/bir_2.jpg'> "+list[i].person+",将于"+daysFromToday(thisDate)+"天后生日<P>")}
}

for (var i in list) {
thisDate=new Date(today.getYear(),list[i].month-1,list[i].date)
if (daysFromToday(thisDate)<0)
thisDate.setYear(today.getYear()+1)
if (daysFromToday(thisDate)==6&&n<4)
{n=n+1
document.write("<font color=##000000 style='font-size:11pt;font-family: 宋体;line-height:1.5'> ","<img src='Images/bir_2.jpg'> "+list[i].person+",将于"+daysFromToday(thisDate)+"天后生日<P>")}
}

for (var i in list) {
thisDate=new Date(today.getYear(),list[i].month-1,list[i].date)
if (daysFromToday(thisDate)<0)
thisDate.setYear(today.getYear()+1)
if (daysFromToday(thisDate)==7&&n<4)
{n=n+1
document.write("<font color=##000000 style='font-size:11pt;font-family: 宋体;line-height:1.5'> ","<img src='Images/bir_2.jpg'> "+list[i].person+",将于"+daysFromToday(thisDate)+"天后生日<P>")}
}
\*这里设置的是按离生日近到远的顺序,显示7天内生日的好友,最多显示4条。具体需要自己改.img那行是字前面的小图标,自己做*\
}

    在body里,你需要的地方加上如下代码(当然这是table的,还有位置等问题,大家自己换代码吧):

<tr>
<td vAlign=center><SCRIPT LANGUAGE="JavaScript"> 
<!--  
  writeNextBirthday(blist)
// -->
</SCRIPT> <SCRIPT LANGUAGE="JavaScript"> 
<!-- hide
function goHist(a) 
{
   history.go(a);
}
//-->
</script></td>
</tr>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值