以前做个人主页的时候,总喜欢把自己的网页搞的很个性,在网上做跑马灯文字,在状态栏显示问候语,或者在状态栏添加时间显示,本代码就是实现了状态栏显示当前时间的物资,火狐没测度,ie下效果完美。
运行效果截图如下:
在线演示地址如下:
http://demo.jb51.net/js/2015/js-status-bar-show-time-demo/
具体代码如下:
<!doctype html public "-//w3c//dtd html 4.0 transitional//en"><html><head><title>状态栏时间显示</title></head><script language="javascript">var timerid = null;var timerrunning = false;function stopclock (){ if(timerrunning) cleartimeout(timerid); timerrunning = false;}function showtime () { var now = new date(); var hours = now.gethours(); var minutes = now.getminutes(); var seconds = now.getseconds() var timevalue = " " + ((hours >12) ? hours -12 :hours) timevalue += ((minutes < 10) ? ":0" : ":") + minutes timevalue += ((seconds < 10) ? ":0" : ":") + seconds timevalue += (hours >= 12) ? " 下午" : " 上午" window.status = timevalue; timerid = settimeout("showtime()",1000); timerrunning = true;}function startclock () { stopclock(); showtime();}</script><body bgcolor="#336699" topmargin="0" leftmargin="0" onload="startclock()">请看左下角!状态栏有时间显示!</body></html>
以上就是本章的全部内容,更多相关教程请访问javascript视频教程!