Posted in Javascript onApril 01, 2013
很久以前就不推荐使用getYear()这个函数,因为在火狐中显示是不正确的,推荐使用getFullYear() 函数。
另外火狐不支持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; }
Js 时间函数getYear()的使用问题探讨
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@