这几天改了个网页要在网页显示时间。找到以下代码:
<div class="date"><script language="javascript"><!-- var today = new Date(); var week; var date; if(today.getDay()==0) week="星期日"; if(today.getDay()==1) week=" 星期一"; if(today.getDay()==2) week="星期二"; if(today.getDay()==3) week=" 星期三"; if(today.getDay()==4) week="星期四"; if(today.getDay()==5) week=" 星期五"; if(today.getDay()==6) week="星期六"; date= (today.getYear())+"年"+(today.getMonth()+1)+"月"+today.getDate()+"日"+" "; document.write(date+week); // --> </script>
但是问题来了,IE下显示正常,火狐下不兼容,年份不能正常显示。
于是找找其他的网站,看看效果,找到个创业方面的网站-挖贝网,嘿嘿,copy下
<head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>兼容FireFox的当前时间的JS脚本</title> </head> <body> <DIV id=time>当前时间 <SCRIPT>document.getElementById('time').innerHTML=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());setInterval("document.getElementById('time').innerHTML=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());",1000);</SCRIPT> </DIV> </body> </html>
问题顺利解决。顺便show下网站上的效果:孕婴童商务网