当前位置:编程学习 > JS >>

我写的javascript显示动态时间的代码~为什么显示不了啊

补充:<script language="JavaScript"; type="text/javascript" > <!-- myDate=new Date(); myHour=myDate.getHours(); if(myHour<12) welcomeString="早上好" ; else if(myHour<18) welcomeString="下午好"; else welcomeString="晚上好"; document.write(myDate.getYear()+"年"+(myDate.getMouth()+1)+"月"+myDate.getDate()+"日 "); document.write(welcomeString); //--> </script>
答案:myDate.getMouth()  写错了,改成 myDate.getMonth() 
 另外,最好用 myDate.getFullYear(),有的浏览器会把myDate.getYear() 按从1900年开始算
你这个不是现实动态时间。只是显示一次的系统时间。
要做动态,需要计时刷新。
其他:myDate.getMouth()拼错了
myDate.getMonth() document.write(myDate.getYear()+"年"+(myDate.getMouth()+1)+"月"+myDate.getDate()+"日 ");
写错了
应该是document.write(myDate.getFullYear()+"年"+(myDate.getMonth()+1)+"月"+myDate.getDate()+"日 "); myDate.getMouth() 打错了。 <script language="JavaScript"; type="text/javascript" >
<!--
myDate=new Date();
myHour=myDate.getHours();

 if(myHour<12)
   welcomeString="早上好" ; 
 else if(myHour<18)
   welcomeString="下午好";
 else 
   welcomeString="晚上好";
   
//document.write(myDate.getYear()+"年"+(myDate.getMouth()+1)+"月"+myDate.getDate()+"日 ");这句有问题
document.write(myDate.getYear()+"年"+(myDate.getHours()+1)+"月"+myDate.getDate()+"日 ");
document.write(welcomeString);
//-->
</script> <script language="JavaScript"; type="text/javascript" >
<!--
var myDate=new Date();
var myHour=myDate.getHours();
 if(myHour<12)
   welcomeString="早上好" ; 
 else if(myHour<18)
   welcomeString="下午好";
 else 
   welcomeString="晚上好";
   
document.write(myDate.getYear()+"年"+myDate.getMonth()+1+"月"+myDate.getDate()+"日 ");
document.write(welcomeString); 
//-->
</script>

上一个:javascript有点不明白,高手指教下!
下一个:javascript轮播图片问题

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,