Js 时间函数getYear()的使用问题探讨
很久以前就不推荐使用getYear()这个函数,因为在火狐中显示是不正确的,推荐使用getFullYear() 函数。
另外火狐不支持innerText这个属性,需要改为textContent才能接收。
然后附上代码
另外火狐不支持innerText这个属性,需要改为textContent才能接收。
然后附上代码
代码如下:
var s,Sys = {},ua = window.navigator.userAgent.toLowerCase(); (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] : (s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] : (s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] : (s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] : (s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0; //浏览器版本号进行测试 //if (Sys.ie) { document.write('IE: ' + Sys.ie); } //if (Sys.firefox){ document.write('Firefox: ' + Sys.firefox);} //if (Sys.chrome){ document.write('Chrome: ' + Sys.chrome);} //if (Sys.opera){ document.write('Opera: ' + Sys.opera);} //if (Sys.safari) { document.write('Safari: ' + Sys.safari); } var today = new Date(); var day,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 = " 星期六"; } date = "今天是:" + (today.getFullYear()) + "年" + (today.getMonth() + 1) + "月" + today.getDate() + "日" + day + ""; if (Sys.firefox) { document.getElementById('time_id').textContent = date; } else { document.getElementById('time_id').innerText = date; }
相关推荐
88274956 2020-11-03
runner 2020-09-01
梦的天空 2020-08-25
移动开发与培训 2020-08-16
ReunionIsland 2020-08-16
lyqdanang 2020-08-16
MyNameIsXiaoLai 2020-07-08
星辰的笔记 2020-07-04
csstpeixun 2020-06-28
letheashura 2020-06-26
liaoxuewu 2020-06-26
sunzhihaofuture 2020-06-21
FEvivi 2020-06-16
坚持着执着 2020-06-16
waterv 2020-06-14
xiaoge00 2020-06-14
firejq 2020-06-14
firstboy0 2020-06-14
e度空间 2020-06-12
zhongweinan 2020-06-10