网页显示在线时间:`
var timeblc = document.getElementById('nowtime');
var weekdays = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
function addZero(t){
if(t<10) return '0'+t;
return t;
}
function showTime(){
var time = new Date();
var t = time.getFullYear()+'年'+getMonthDay(time)+getWeekday(time)+getHMS(time);
timeblc.innerHTML = t;
setTimeout('showTime()',1000); //这里!!
}
function getMonthDay(time){
var m = addZero(time.getMonth()+1);
var d = addZero(time.getDate());
var str = m+'月'+d+'日';
return str;
}
function getWeekday(time){
var str = weekdays[time.getDay()];
return str;
}
function getHMS(time){
var h = addZero(time.getHours());
var m = addZero(time.getMinutes());
var s = addZero(time.getSeconds());
var str = h+':'+m+':'+s;
return str;
}
showTime();`
代码注释处,第一个参数若不添加引号则引发内存溢出:
网上查过,可知加引号则会在全局内寻找,不加则是在局部变量寻找,然而没找到有关溢出和查询变量方式的关系。
求教!
慕丝7291255
HUH函数
相关分类