|
热门文章 |
|
|
|
相关文章 |
|
没有相关文章 |
|
|
动态显示当前时间并显示当前是上午还是下午 |
来源:源码爱好者 更新时间:2011/1/2 22:19:07 阅读次数: 我要投稿 |
|
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>New Page 1</title> </head> <body onload="startclock()"> <script language=JavaScript> var timerID = null; var timerRunning = false; function stopclock (){ if(timerRunning) clearTimeout(timerID); timerRunning = false;} function startclock () { stopclock(); showtime();} function showtime () { var now = new Date(); var hours = now.getHours(); var minutes = now.getMinutes(); var seconds = now.getSeconds() var timeValue = "" +((hours >= 12) ? "下午 " : "上午 " ) timeValue += ((hours >12) ? hours -12 :hours) timeValue += ((minutes < 10) ? ":0" : ":") + minutes timeValue += ((seconds < 10) ? ":0" : ":") + seconds document.clock.thetime.value = timeValue; timerID = setTimeout("showtime()",1000); timerRunning = true;} </SCRIPT> <form name=clock > <input name=thetime style="font-size: 9pt;color:#000000;border:0" size=12> </form> </body> </html> |
特效说明: |
Js获取当前的时间,并在时间前加上“上午”、“下午”字样,让浏览者一目了然。 |
|
上一篇文章: 中英文双语日期选择器下一篇文章: JavaScript日历生成器 |
|
|