一点一滴,编程人生

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  69 随笔 :: 0 文章 :: 25 评论 :: 0 Trackbacks
今天查看某网站时发现其日期显示的不对,显示为:109年12月28日 星期一(我用的是chrome),后来在IE中测试,没有问题,显示为:2009年12月28日,最后在FF中测试也是有问题的。我查看其源代码,如下:
 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+""+"&nbsp;"+"星期"+theday);
20 </script>

看来是第6行的getYear函数出现了问题,我便用getFullYear函数替换它,问题解决了。看来IE与其它浏览器的getYear函数实现是不同的,以后做开发时要注意这个特殊问题。
posted on 2009-12-28 11:49 writegull 阅读(384) 评论(0)  编辑  收藏 所属分类: javascript

只有注册用户登录后才能发表评论。


网站导航: