回复 3楼 foktime
你好!~~~~谢谢你的帮助,您的代码我优化了一下,大致没有变化~~~~~~我还有不明白的是,settimeout()方法和setinterval()方法都要放在类似与<DIV>之类的"容器"里面运行吗???源代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<script type="text/javascript">
/*function $(id){
return document.getElementById(id);
}*/
//这段去掉~~~~~~~~~
function showTime(){
setInterval(clock,1000);
}
function clock(){
var myDate = new Date();
var year = myDate.getFullYear();
var year = new String(year);
var month = myDate.getMonth()+1;
var month = new String(month);
var date = myDate.getDate();
var date = new String(date);
var hour = myDate.getHours();
var hour = new String(hour);
var minute = myDate.getMinutes();
var minute = new String(minute);
var second = myDate.getSeconds();
var second = new String(second);
var str = '';
str += year+"年"+month+"月"+date+"日"+hour+"时"+minute+"分"+second+"秒";
var ret_y="";
var array_year=year.split("");
for(var i=0;i<array_year.length;i++){
ret_y+='<img src="'+array_year[i]+'.gif">';
}
str += ret_y;
str += "年\t";
//$('showtime').innerHTML= str;
var ret_m="";
var array_month=month.split("");
for(var i=0;i<array_month.length;i++){
ret_m+='<img src="'+array_month[i]+'.gif">';
}
str += ret_m;
str += "月\t";
var ret_d="";
var array_date=date.split("");
for(var i=0;i<array_date.length;i++){
ret_d+='<img src="'+array_date[i]+'.gif">';
}
str += ret_d;
str += "日\t";
var ret_h="";
var array_hour=hour.split("");
for(var i=0;i<array_hour.length;i++){
ret_h+='<img src="'+array_hour[i]+'.gif">';
}
str += ret_h;
str += "时\t";
var ret_m="";
var array_minute=minute.split("");
for(var i=0;i<array_minute.length;i++){
ret_m+='<img src="'+array_minute[i]+'.gif">';
}
str += ret_m;
str += "分\t";
var ret_s="";
var array_second=second.split("");
for(var i=0;i<array_second.length;i++){
ret_s+='<img src="'+array_second[i]+'.gif">';
}
str += ret_s;
str += "秒\t";
//$('showtime').innerHTML = str; 这段改为~~~~~~
document.getElementById("showtime").innerHTML=str;
}
</script>
<!--我觉得这样更加容易理解!!!-->
<body onload="showTime()">
<div id="showtime"></div>
</body>
</html>