当前位置:编程学习 > 网站相关 >>

建站全攻略(11)

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

具体方法:

在网页HTML源文件的<body>和</body>之间你想要时间显示的空白处点击鼠标,输入:

<script language=”Javascript”>

<!--

var enabled = 0; today = new Date();

var day; var date;

if(today.getDay()==0) day = "星期日 "

if(today.getDay()==1) day = "星期一 "

if(today.getDay()==2) day = "星期二 "

if(today.getDay()==3) day = "星期三 "

if(today.getDay()==4) day = "星期四 "

if(today.getDay()==5) day = "星期五 "

if(today.getDay()==6) day = "星期六 "

document.fgColor = " FF0072";

date1 =(today.getYear()) + "年" + (today.getMonth() + 1 ) + "月" + today.getDate() + "日 " ;

date2 = day ;

document.write(date1.fontsize(2));

document.write(date2.fontsize(2));

document.write("<span id='clock'></span>");

var now,hours,minutes,seconds,timeValue;

function showtime(){

now = new Date();

hours = now.getHours();

minutes = now.getMinutes();

seconds = now.getSeconds();

timeValue = (hours >= 12) ? "下午 " : "上午 ";

timeValue += hours+ ":";

timeValue += ((minutes < 10) ? "0" : "") + minutes + ":";

timeValue += ((seconds < 10) ? "0" : "") + seconds + "";

clock.innerHTML = timeValue;

setTimeout("showtime()",100);

}

showtime();

-->

</script>

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

上一个:建站全攻略(12)
下一个:建站全攻略(10)

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,