<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>简易时钟</title>
<style type="text/css">
h1{
text-align: center;
}
#box{
width: 300px;
height: 60px;
background-color: saddlebrown;
text-align: center;
line-height: 60px;
font-size: 50px;
color: white;
margin: 0 auto;
}
</style>
</head>
<body>
<script type="text/javascript">
window.onload = function(){
setInterval(NowTime,1000);
NowTime();
function NowTime(){
var box = document.getElementById('box');
var a = new Date();
var b = a.getHours();
var c = a.getMinutes();
var d = a.getSeconds();
box.innerHTML = check(b)+":"+check(c)+":"+check(d);
};
function check(val){
if(val < 10){
return("0" + val)
}else{
return(val)
}
}
}
</script>
<h1>简易时钟</h1>
<div id="box" ></div>
</body>
</html>
js获取当前时间,自动刷新(简易时钟)
最新推荐文章于 2023-12-24 08:08:14 发布