今天查看某網(wǎng)站時(shí)發(fā)現(xiàn)其日期顯示的不對(duì),顯示為:109年12月28日 星期一(我用的是chrome),后來(lái)在IE中測(cè)試,沒(méi)有問(wèn)題,顯示為:2009年12月28日,最后在FF中測(cè)試也是有問(wèn)題的。我查看其源代碼,如下:
1 <script language="JavaScript" type="text/javascript">
2 var curdate=new Date();
3 day=curdate.getDay();
4 mm=curdate.getMonth()+1;
5 date=curdate.getDate();
6 year=curdate.getYear();
7 var theday;
8 switch(day)
9 {
10 case 1: theday="一"; break;
11 case 2: theday="二"; break;
12 case 3: theday="三"; break;
13 case 4: theday="四"; break;
14 case 5: theday="五"; break;
15 case 6: theday="六"; break;
16 case 0: theday="日"; break;
17 }
18 alert(year);
19 document.write(year+"年"+mm+"月"+date+"日"+" "+"星期"+theday);
20 </script>
看來(lái)是第6行的getYear函數(shù)出現(xiàn)了問(wèn)題,我便用getFullYear函數(shù)替換它,問(wèn)題解決了。看來(lái)IE與其它瀏覽器的getYear函數(shù)實(shí)現(xiàn)是不同的,以后做開(kāi)發(fā)時(shí)要注意這個(gè)特殊問(wèn)題。