第一次用 javascript 写时间代码 学习中……

小菜鸟战斗机 2018-3-28 170

<DIV>学习JavaScript&nbsp;的第一课</DIV>

<DIV>&nbsp;</DIV>

<DIV>&lt;div id="time"&gt;&lt;/div&gt;</DIV>

<DIV>&lt;script type="text/javascript" language="javascript"&gt;</DIV>

<DIV>function ff(){<BR>&nbsp;var date= new Date();&nbsp;&nbsp; // 定义日期<BR>&nbsp;var year=date.getFullYear();&nbsp; // 取当前年份<BR>&nbsp;var month=date.getMonth()+1;&nbsp; //取当前月份<BR>&nbsp;var day=date.getDate();&nbsp; //取当前天数<BR>&nbsp;var hour=date.getHours();&nbsp; //取当前小时<BR>&nbsp;var minm=date.getMinutes();&nbsp; //取当前分钟<BR>&nbsp;var sed=date.getSeconds();&nbsp; //取当前秒<BR>&nbsp;&nbsp;sed =(sed&lt;10)?+'0'+sed:sed;&nbsp; // 秒数少于10,在前面加0<BR>&nbsp;var timeH=year+'年'+month+'月'+day+'日 '+hour+':'+minm+':'+sed;&nbsp; // 结合<BR>&nbsp;var time=document.getElementById('time');&nbsp; //把 div&nbsp;的id取出来<BR>&nbsp;time.innerHTML=timeH;&nbsp;&nbsp;<BR>}</DIV>

<DIV>window.setInterval('ff()',1000); </DIV>

<DIV>&lt;/script&gt;</DIV>

<DIV>&nbsp;</DIV>

<DIV>&nbsp;</DIV>

<DIV>&nbsp;</DIV>


最新回复 (0)
返回