JavaScript timer运用示例:
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 5 <title>switch多重判断语句+timer</title> 6 <style type="text/css"> 7 <!-- 8 body,td,th { 9 font-size: 12px; 10 } 11 body { 12 margin-left: 10px; 13 margin-top: 10px; 14 margin-right: 10px; 15 margin-bottom: 10px; 16 } 17 --> 18 </style> 19 <script> 20 timer = window.setInterval("showDate()",500);//设置时钟 21 function showDate(){ 22 var obj,date; 23 obj = new Date(); //显示为时间格式“Tue May 27 2014 11:00:22 GMT+0800” 24 date = obj.getFullYear() + "-"; //当前年份 25 date += obj.getMonth()+1+ "-"; //当前的月份需要加上“1” 26 date += obj.getDate()+ " "; 27 date += obj.getHours() + ":"; 28 date += obj.getMinutes() + ":"; 29 date += obj.getSeconds(); 30 document.getElementById("tm").innerHTML = date; //向id为"tm"的div添加内容 31 } 32 </script> 33 </head> 34 <body> 35 <div id="tm"></div> 36 <div align="center"> 37 <?php 38 setlocale(LC_TIME,"chs"); //设置本地环境 39 $weekday = strftime("%A"); //声明变量$weekday的值 40 switch ($weekday){ //switch语句,判断$weekday的值 41 case "星期一": //如果变量的值为“星期一” 42 echo "今天是$weekday ,新的一周开始了。"; 43 break; 44 case "星期二": //如果变量的值为“星期二” 45 echo "今天是$weekday ,保持昨天的好状态,继续努力!"; 46 break; 47 case "星期三": //如果变量的值为“星期三” 48 echo "今天是$weekday ,真快啊,过去1/2周了。"; 49 break; 50 case "星期四": //如果变量的值为“星期四” 51 echo "今天是$weekday ,再上1天又放假了:)"; 52 break; 53 case "星期五": //如果变量的值为“星期五” 54 echo "今天是$weekday ,好好想想明天去那里玩。"; 55 break; 56 default: //默认值 57 echo "今天是$weekday , HOHO~~,可以放松了。"; 58 break; 59 } 60 ?> 61 62 </div> 63 </body> 64 </html>