您的位置:首页 > Web前端 > JavaScript

JavaScript动态显示系统时间

2017-08-29 10:59 375 查看
html文件如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>当前系统时间</title>
<link rel="stylesheet" href="style.css"  />

<script language="javascript" type="text/javascript">
<!--
window.onload = function(){
showTime();
}
function checkTime(i)
{
if (i<10)
{i="0" + i}
return i
}
function showTime()
{
var now=new Date();
var year=now.getFullYear();
var month=now.getMonth()+1;
var day=now.getDate();
var h=now.getHours();
var m=now.getMinutes();
var s=now.getSeconds();
m=checkTime(m)
s=checkTime(s)

var weekday=new Array(7)
weekday[0]="星期日"
weekday[1]="星期一"
weekday[2]="星期二"
weekday[3]="星期三"
weekday[4]="星期四"
weekday[5]="星期五"
weekday[6]="星期六"

document.getElementById("show").innerHTML=""+year+"年"+month+"月"+day+"日 "+weekday[now.getDay()]+h+":"+m+":"+s;
t=setTimeout('showTime()',500)
}
//-->
</script>
</head>
<body>
<div class="content1">
<div id="show">显示时间的位置</div>
</div>
</body>
</html>


css文件如下:

@charset "UTF-8";
/* CSS Document */
div,img{
margin:0;
padding:0;
border:0;
}
.content1 {
background: url(image/new.jpg) no-repeat;
width: 1004px;
height: 613px;
margin: 0 auto;
position: relative;
}
#show {
position: absolute;
top: 108px;
left: 27px;
color: #F00;
}
.content2 {
background: url(image/kaoyan.jpg) no-repeat;
width: 1004px;
height: 613px;
margin: 0 auto;
position: relative;
}
.txtshow {
position: absolute;
top: 126px;
left: 477px;
color: #000;
}
#timeShow{
color:#f00;
font-weight:bold;
font-size:24px;
}
.content3{
background:url(image/product.jpg) no-repeat;
width:1200px;
height:398px;
margin:0 auto;
position:relat
ce39
ive;
}
.time{
position:absolute;
top:122px;
left:46%;
line-height:22px;
font-size:14px;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息