js实现在网页上简单显示时间的方法
本文实例讲述了js实现在网页上简单显示时间的方法。分享给大家供大家参考。具体如下:
这是一款网页时钟JS代码,纯javascript实现,显示时、分、秒。网页时间显示、网页时钟有很多,这个真的挺简易的,美工好的朋友可在此基础上进一步美化完善
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<title>简易网页时钟</title>
<style>
body,div{margin:0;padding:0;}
body{color:#fff;font:16px/1.5\5fae\8f6f\96c5\9ed1;}
#clock{width:300px;text-align:center;background:#1a1a1a;margin:10pxauto;padding:20px0;}
span{color:#000;width:80px;line-height:2;background:#fbfbfb;border:2pxsolid#b4b4b4;margin:010px;padding:010px;}
</style>
<script>
window.onload=function()
{
varoClock=document.getElementById("clock");
varaSpan=oClock.getElementsByTagName("span");
setInterval(getTimes,1000);
getTimes();
functiongetTimes()
{
varoDate=newDate();
varaDate=[oDate.getHours(),oDate.getMinutes(),oDate.getSeconds()];
for(variinaDate)aSpan[i].innerHTML=format(aDate[i])
}
functionformat(a)
{
returna.toString().replace(/^(\d)$/,"0$1")
}
}
</script>
</head>
<body>
<divid="clock">
<span></span>点<span></span>分<span></span>秒
</div>
</body>
</html>
希望本文所述对大家的javascript程序设计有所帮助。
热门推荐
10 诗词送行祝福语大全简短
11 新房开工吉日祝福语简短
12 50多岁生日简短祝福语
13 安徽疫情祝福语简短英语
14 农民朋友发财祝福语简短
15 对生活祝福语简短精辟
16 搬家词简短祝福语朋友
17 女神结婚快乐祝福语简短
18 文学短句祝福语大全简短