当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 比较简洁的JavaScript 实时显示时间的脚本 修正版

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 比较简洁的JavaScript 实时显示时间的脚本 修正版


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 92 ::
收藏到网摘: n/a

比较简洁的JavaScript 实时显示时间的脚本代码。大家可以看下,已经修改好了。 JavaScript显示时间,时间还在走动着!不是一个静态的效果!
function Time() 定义一个函数。
{ if (!document.layers&&!document.all)
return 由于IE与Netscape对JavaScript的解释不同,造成浏览的效果不同,所以要分别写代码。这句话判断一下用户所使用的浏览器,如果两者都不是,就返回。
var timer=new Date() 定义一个新的变量,名字为timer,为一个新的Date的对象。
var hours=Timer.getHours()
var minutes=Timer.getMinutes()
var seconds=Timer.getSeconds() 分别定义3个变量,获得当前“小时”,“分钟”,“秒”的值。
var noon="AM" if (hours>12)
{ noon="PM" hours=hours-12 }
if (hours==0)
hours=12 定义一个名为“noon”的变量,当“小时”数大于12时,其值为PM,同时所得值减12;当“小时”数小于12时,其值为AM。
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds 如果“分钟”数或“秒”数小于9,则在前面加一个“0”。
myclock="<font color=blue>" +hours+":"+minutes+":" +seconds+" "+noon+"</b></font>" 用一个新变量把“小时,分,秒”结合起来。
if (document.layers)
{ document.layers.position.
document.write(myclock)
document.layers.position.document.close() } 如果浏览器是Netscape,就输出myclock,同时用于IE的代码就停止执行。
else if (document.all)
position.innerHTML=myclock 否则,浏览器是IE,就输出myclock。
setTimeout("Time()",1000) 每1000毫秒,调用一次Time函数,即一秒动一次。
onload="Time()" 页面装载时,调用Time()函数。
点击运行可以看到效果:
[Ctrl+A 全选 提示:你可先修改部分代码,再按运行]

下面这个是最简单的显示日期的方式
点击运行可以看到效果:
[Ctrl+A 全选 提示:你可先修改部分代码,再按运行]