javascript 显示当前系统时间代码_Javascript教程-查字典教程网
javascript 显示当前系统时间代码
javascript 显示当前系统时间代码
发布时间:2016-12-30 来源:查字典编辑
摘要:1.在中加入下列代码复制代码代码如下:vartimerID=null;vartimerRunning=false;functionstopc...

1.在<head></head>中加入下列代码

复制代码 代码如下:

<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>

2.在<body>中加入下列代码

onload=startclock()

3.在显示时间的位置插入下列代码,建议使用表格定位

[code]

<form name=clock >

<input name=thetime size=12>

</form>

//只获得当前系统日期的函数

<script language="JavaScript" type="text/javascript">

document.write(new Date().getYear()+"-"+(new Date().getMonth()+1)+"-"+new Date().getDate());

</script>

http://www.jb51.net/article/12786.htm

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新Javascript教程学习
    热门Javascript教程学习
    编程开发子分类