码迷,mamicode.com
首页 > 编程语言 > 详细

JavaScript 时间特效 显示当前时间

时间:2015-10-14 14:14:39      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>显示当前时间</title>
<script type="text/javascript">
function showtime(){//创建函数
   var now_time = new Date();//创建时间对象的实例
   var hours = now_time.getHours();//获得当前小时数
   var minutes = now_time.getMinutes();//获得当前分钟数
   var seconds = now_time.getSeconds();//获得当前秒数
   var timer = ""+ ((hours>12)?hours -12:hours);//将小时数值赋予变量timer
   timer+=((minutes<10)?":0":":")+minutes;//将分钟数赋予变量timer
   timer+=((seconds<10)?":0":":")+seconds;//将秒数赋予timer
   timer+=""+((hours>12)?" PM":" AM");//将字符AM或PM赋予变量timer
   document.clock.show.value=timer;//在名为clock的表单中输出变量timer的值
   setTimeout("showtime()",1000);//设置每隔一秒钟自动调用一次showtime()函数
}
</script>
</head>
<body onload="showtime()" >
<form name="clock" onsubmit="0">
<input type="text" name="show" size="10"
style=" border-width: 3;">
</form>
</script>
</body>
</html>

JavaScript 时间特效 显示当前时间

标签:

原文地址:http://www.cnblogs.com/liangxiaoyu/p/4877162.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!