关于 setTimeout 和 setInterval 的问题
window.onload = function(){
showTime();
}
function showTime(){
var oDiv = document.getElementById("fenx"),
myDate = new Date(),
year = myDate.getFullYear(),
month = myDate.getMonth() + 1,
date = myDate.getDate(),
hour = myDate.getHours(),
minute = myDate.getMinutes(),
second = myDate.getSeconds(),
day = myDate.getDay();
weekDay = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六",];
if(second < 10 ){
second = "0" + second;
}
oDiv.innerHTML =year + "年" + month + "月" + date + "日" + hour + "时" + minute + "分" + second + "秒" ;
setTimeout(showTime,500);
}
setTimeout(showTime,500); setTimeout不是指定时间后执行一次吗,用它时间为什么还会不停的刷新呢。
反而用了setInterval(showTime,500); 后浏览器后卡死, 貌似是进了死循环一样 !!