日期:2014-05-17  浏览次数:20916 次

如何在网页中添加时间(钟表),谢谢
我想在网页中添加个钟表,或者其它格式的时间,用代码怎么写呢
谢谢

------解决方案--------------------
<html>
<script>
var days=[ "星期天 ", "星期一 ", "星期二 ", "星期三 ", "星期四 ", "星期五 ", "星期六 "];
function goTime(){
var time = new Date();
var year = time.getFullYear();
var month = time.getMonth()+1;//返回0-11,所以+1
var date = time.getDate();
var day = time.getDay();//返回0-6
var hour = time.getHours();
var minute = time.getMinutes();
var second = time.getSeconds();
var str = "现在是: "+year+ "年 "+month+ "月 "+date+ "日 "+days[day];
str += hour+ "点 "+minute+ "分 "+second+ "秒 ";
window.clock.innerHTML = str;
}
window.onload=function(){
window.clock=document.getElementById( "clock ");
window.setInterval( "goTime() ",1000);
}
</script>

<body>
<span id= "clock "> <span>
</body>
</html>