1、区域加入以下代码XML/HTML代码 function tick() var hours, minutes, seconds, xfile; var intHours, intMinutes, intSeconds; var today; today = new Date(); intHours = today.getHours(); intMinutes = today.getMinutes(); intSeconds = today.getSeconds(); if (intHours = 0) hours = 12: xfile = 午夜 else if (intHours 12) ho
2、urs = intHours+:上午 else if (intHours = 12) 正午 else intHoursintHours = intHours - 12 hours = intHours + 下午 if (intMinutes 10) minutes = 0+intMinutes+ minutes = intMinutes+ if (intSeconds seconds = +intSeconds+ seconds = intSeconds+ timeString = xfile+hours+minutes+seconds; Clock.innerHTML = timeStrin
3、g; window.setTimeout(tick();, 100); window.onload = tick;复制代码第二步.将下面的代码加入html文件任意需要的地方 1. 2. today=new Date(); 3. function initArray() 4. this.length=initArray.arguments.length 5. for(var i=0;i ); 22. 三、显示日期,星期,时间格式的代码 如:2008年11月27日星期四 下午2:17:36 1. 2. 3. 4. today=new Date(); 5. function initArray()
4、6. this.length=initArray.arguments.length 7. for(var i=0; 8. thisi+1=initArray.argumentsi 9. var d=new initArray( 15. 17. document.write( 18. font color=#ecc1c1 style= 19. today.getYear(), 20. today.getMonth()+1, 21. today.getDate(), 22. dtoday.getDay()+1, 23. 24. 25. 26. 27. 28. 29. function tick()
5、 30. var hours, minutes, seconds, xfile; 31. var intHours, intMinutes, intSeconds; 32. var today; 33. today = new Date(); 34. intHours = today.getHours(); 35. intMinutes = today.getMinutes(); 36. intSeconds = today.getSeconds(); 37. if (intHours = 0) 38. hours = 39. xfile = 40. else if (intHours 41.
6、 hours = intHours+ 42. xfile = 43. else if (intHours = 12) 44. hours = 45. xfile = 46. else 47. intHours = intHours - 12 48. hours = intHours + 49. xfile = 50. 51. if (intMinutes 52. minutes = 53. else 54. minutes = intMinutes+ 55. 56. if (intSeconds 57. seconds = 58. else 59. seconds = intSeconds+
7、60. 61. timeString = xfile+hours+minutes+seconds; 62. Clock.innerHTML = timeString; 63. window.setTimeout( 64. 65. window.onload = tick; 66. 67. /DIV四、显示来访者的停留时间 如:停留时间: 00:15script language=javascript 4. var ap_name = navigator.appName; 5. var ap_vinfo = navigator.appVersion; 6. var ap_ver = parseF
8、loat(ap_vinfo.substring(0,ap_vinfo.indexOf(); 7. 8. var time_start = new Date(); 9. var clock_start = time_start.getTime(); 10. var dl_ok=false; 11. 12. function init () 13. 14. if(ap_name=Netscape & ap_ver=3.0) 15. dl_ok=true; 16. return true; 17. 18. 19. function get_time_spent () 20. 21. var time
9、_now = new Date(); 22. return(time_now.getTime() - clock_start)/1000); 23. 24. 25. function show_secs () / show the time user spent on the side 26. 27. var i_total_secs = Math.round(get_time_spent(); 28. var i_secs_spent = i_total_secs % 60; 29. var i_mins_spent = Math.round(i_total_secs-30)/60); 30
10、. var s_secs_spent = + (i_secs_spent9) ? i_secs_spent : + i_secs_spent); 31. var s_mins_spent = + (i_mins_spent i_mins_spent : + i_mins_spent); 32. document.fm0.time_spent.value = s_mins_spent + + s_secs_spent; 33. window.setTimeout(show_secs() 34. 35. 36. / - 37. 38. FORM name=fm0 onSubmit=FONT COL
11、OR=#6060FF 39. INPUT type=text name=time_spent size=7 onFocus=this.blur()/FORM而且还要在你主页源文件中加入下面的代码BODY onLoad=init(); window.setTimeout(,1);五、显示当前日期与时间 如:现在是: 2008年11月27日 14:18:59 时间不走动 4. - 5. now = new Date() 6. hour = now.getHours() 7. if (hour 12) 8. document.write( + now.toLocaleString() 9. else
12、 if (hour = 18) 12. document.write( 13. 14. / -六、浏览器状态栏显示的时钟 如:2:20 P.M. 星期四 在状态栏显示run(); timerONE=window.setTimeout/BODYSCRIPT LANGUAGE= 5. 12) ? hours -12 :hours) 23. current += (minutes 10) ? :) + minutes 24. current += (seconds = 12) ? P.M. A.M. 26. if(day=0)var weekday = 星期日 27. if(day=1)var we
13、ekday = 星期一 28. if(day=2)var weekday = 星期二 29. if(day=3)var weekday = 星期三 30. if(day=4)var weekday = 星期四 31. if(day=5)var weekday = 星期五 32. if(day=6)var weekday = 星期六 33. current +=(weekday) 34. window.status=current; 35. timeID = setTimeout(time() 36. timeRunning = true; 37. 38. function run() 39.
14、stop(); 40. time(); 41. 42. 43. /- 44. -hide script from old browsers 5. document.write( + document.lastModified + ) 6. / end hiding - 7. 相关帖子 * 征服RIA:函数式编程的原理收藏 分享 * 0 * 顶 * 踩本是后山人;偶作前堂客。醉舞经阁半卷书;坐井说天阔。大志戏功名;海斗量福祸。待到囊中羞涩时;怒指乾坤错。最快的美国主机,支持支付宝付款,中文面板,无限网站!分享到: 人人网 QQ空间 XX收藏 开心网 新浪微博 Google书签lht272 * 发
15、短消息 * 加为好友lht272 (百科“砖”家) 当前离线UID 1728 帖子 11276 精华 2 积分 12831 阅读权限 100 来自 山沟 在线时间 2374 小时 注册时间 2009-1-14 最后登录 2010-12-14 个人空间 查看详细资料版主Rank: 7Rank: 7威望 307 银币 42055 金币 12647 优秀版主2#发表于 2010-9-10 21:14 | 只看该作者八、实时走动的数字时钟 如:22:03 2. function tick() 3. var hours, minutes, seconds, xfile; 4. var intHours,
16、 intMinutes, intSeconds; 5. var today; 6. today = new Date(); 7. intHours = today.getHours(); 8. intMinutes = today.getMinutes(); 9. intSeconds = today.getSeconds(); 10. if (intHours = 0) 11. hours = 12. xfile = 13. else if (intHours 14. hours = intHours+ 15. xfile = 16. else if (intHours = 12) 17.
17、hours = 18. xfile = 19. else 20. intHoursintHours = intHours - 12 21. hours = intHours + 22. xfile = 23. 24. if (intMinutes 25. minutes = 26. else 27. minutes = intMinutes+ 28. 29. if (intSeconds 30. seconds = 31. else 32. seconds = intSeconds+ 33. 34. timeString = xfile+hours+minutes+seconds; 35. C
18、lock.innerHTML = timeString; 36. window.setTimeout( 37. 38. window.onload = tick; 40. 41. 九、根据不同的时间显示不同的问候语 如:午安!方法:在主页中你需要的地方加入以下代码:LiveScript 4. now = new Date(),hour = now.getHours() 5. if(hour 6)document.write(明天不用上班了吗?) 6. else if (hour 8)document.write(全新的一天! 7. else if (hour 12)document.write(早安! 8. else if (hour 14)document.write(外面太阳大吗? 9. else if (hour 18)document.write( 10. else if (hour 22)document.write(晚上好! 11. else if (hour 13.