javascript特效--制作背景电子钟(整点时祝贺生日快乐)
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>背景时钟</title> 6 7 </head> 8 <body> 9 <p id="bgclockshade" style="position:absolute;visibility:visible;font-family:Verdana;color:#FFAAAA;font-size:100px;top:10px;left:152px"> </p> 10 11 12 13 <script type="text/javascript"> 14 15 function clockDemo(){ 16 //先获得时间 17 var time=new Date(); 18 var hour=time.getHours(); //时 19 var minute=time.getMinutes(); //分 20 var second=time.getSeconds(); //秒 21 22 if(eval(hour)<10) hour="0"+hour; //如果不满10 23 if(eval(minute)<10) minute="0"+minute; 24 if(eval(second)<10) second="0"+second; 25 var timeStr=hour+":"+minute+":"+second; 26 if(eval(hour)==0 && eval(minute)==0 && eval(second)==0) alert("生日快乐!"); 27 28 var bgclockshade=document.getElementById("bgclockshade"); 29 30 31 32 bgclockshade.innerHTML=timeStr; 33 34 35 var timer= setTimeout("clockDemo()",200); //没0.2秒刷新时间 36 37 } 38 39 clockDemo(); //启动入口 40 </script> 41 42 </body> 43 </html>