萬盛學電腦網

 萬盛學電腦網 >> 網頁制作 >> 網頁設計 >> Js 時間函數getYear()的使用問題探討

Js 時間函數getYear()的使用問題探討

class="area"> 很久以前就不推薦使用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; 
copyright © 萬盛學電腦網 all rights reserved