建站全攻略(11)

4.显示当前日期和时间 可以让来访者知道现在的时间,而且会随着系统时间随时调整。

具体方法:

在网页HTML源文件的

1<body>和</body>

之间你想要时间显示的空白处点击鼠标,输入:

 1<script language="”JavaScript”">   
 2  
 3<!--   
 4  
 5var enabled = 0; today = new Date();   
 6  
 7var day; var date;   
 8  
 9if(today.getDay()==0) day = "星期日 "   
10  
11if(today.getDay()==1) day = "星期一 "   
12  
13if(today.getDay()==2) day = "星期二 "   
14  
15if(today.getDay()==3) day = "星期三 "   
16  
17if(today.getDay()==4) day = "星期四 "   
18  
19if(today.getDay()==5) day = "星期五 "   
20  
21if(today.getDay()==6) day = "星期六 "   
22  
23document.fgColor = " FF0072";   
24  
25date1 =(today.getYear()) + "年" + (today.getMonth() + 1 ) + "月" + today.getDate() + "日 " ;   
26  
27date2 = day ;   
28  
29document.write(date1.fontsize(2));   
30  
31document.write(date2.fontsize(2));   
32  
33document.write("<span id='clock'></span>");   
34  
35var now,hours,minutes,seconds,timeValue;   
36  
37function showtime(){   
38  
39now = new Date();   
40  
41hours = now.getHours();   
42  
43minutes = now.getMinutes();   
44  
45seconds = now.getSeconds();   
46  
47timeValue = (hours >= 12) ? "下午 " : "上午 ";   
48  
49timeValue += hours+ ":";   
50  
51timeValue += ((minutes < 10) ? "0" : "") + minutes + ":";   
52  
53timeValue += ((seconds < 10) ? "0" : "") + seconds + "";   
54  
55clock.innerHTML = timeValue;   
56  
57setTimeout("showtime()",100);   
58  
59}   
60  
61showtime();   
62  
63\-->   
64  
65</script>

保存退出。这里就不要再做什么替换了。

Published At
Categories with 站长专区
comments powered by Disqus