小解决办法,实测,可用,希望对大家有所帮助。
调用:
<HTML> <HEAD> <META http-equiv='Content-Type' content='text/html; charset=gb2312'> <TITLE>在状态栏中显示当前时间和日期</TITLE> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin function runClock() { theTime = window.setTimeout("runClock()", 1000); var today = new Date(); var display= today.toLocaleString(); status=display; } // End --> </SCRIPT> </HEAD> <BODY onLoad="runClock()"> </BODY></HTML>
实现:
1 <SCRIPT language=JavaScript> 2 var osd = " " 3 osd +=""; 4 var timer; 5 var msg = ""; 6 function scrollMaster () { 7 msg = customDateSpring(new Date()) 8 clearTimeout(timer) 9 msg += " " + showtime() + " " + osd 10 for (var i= 0; i < 100; i++){ 11 msg = " " + msg; 12 } 13 scrollMe() 14 } 15 function scrollMe(){ 16 window.status = msg; 17 msg = msg.substring(1, msg.length) + msg.substring(0,1); 18 timer = setTimeout("scrollMe()", 200); 19 } 20 function showtime (){ 21 var now = new Date(); 22 var hours= now.getHours(); 23 var minutes= now.getMinutes(); 24 var seconds= now.getSeconds(); 25 var months= now.getMonth(); 26 var dates= now.getDate(); 27 var years= now.getYear(); 28 var timeValue = "" 29 timeValue += ((months >9) ? "" : " ") 30 timeValue += ((dates >9) ? "" : " ") 31 timeValue = ( months +1) 32 timeValue +="/"+ dates 33 timeValue +="/"+ years 34 var ap="A.M." 35 if (hours == 12) { 36 ap = "P.M." 37 } 38 if (hours == 0) { 39 hours = 12 40 } 41 if(hours >= 13){ 42 hours -= 12; 43 ap="P.M." 44 } 45 var timeValue2 = " " + hours 46 timeValue2 += ((minutes < 10) ? ":0":":") + minutes + " " + ap 47 return timeValue2; 48 } 49 function MakeArray(n) { 50 this.length = n 51 return this 52 } 53 monthNames = new MakeArray(12) 54 monthNames[1] = "一月" 55 monthNames[2] = "二月" 56 monthNames[3] = "三月" 57 monthNames[4] = "四月" 58 monthNames[5] = "五月" 59 monthNames[6] = "六月" 60 monthNames[7] = "七月" 61 monthNames[8] = "八月" 62 monthNames[9] = "九月" 63 monthNames[10] = "十月" 64 monthNames[11] = "十一月" 65 monthNames[12] = "十二月" 66 daysNames = new MakeArray(7) 67 daysNames[1] = "周日" 68 daysNames[2] = "周一" 69 daysNames[3] = "周二" 70 daysNames[4] = "周三" 71 daysNames[5] = "周四" 72 daysNames[6] = "周五" 73 daysNames[7] = "周六" 74 function customDateSpring(oneDate) { 75 var theDay = daysNames[oneDate.getDay() +1] 76 var theDate =oneDate.getDate() 77 var theMonth = monthNames[oneDate.getMonth() +1] 78 var dayth="号" 79 if ((theDate == 1) || (theDate == 21) || (theDate == 31)) { 80 dayth="st"; 81 } 82 if ((theDate == 2) || (theDate ==22)) { 83 dayth="nd"; 84 } 85 if ((theDate== 3) || (theDate == 23)) { 86 dayth="rd"; 87 } 88 return theDay + ", " + theMonth + " " + theDate + dayth + "," 89 } 90 scrollMaster(); 91 </SCRIPT>