<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<!--
1、原型编程,数字时钟
-->
<p>时钟</p>
<script>
function setNum(num) {
return num < 10 ? '0' + num : num;
}
Date.prototype.currentTime = function (element) {
var year = this.getFullYear(),
month = this.getMonth(),
day = this.getDay(),
hour = this.getHours(),
minutes = this.getMinutes(),
sec = this.getSeconds();
month = setNum(month);
day = setNum(day);
hour = setNum(hour);
minutes = setNum(minutes);
sec = setNum(sec);
return year + '-' + month + '-' + day + ' ' + hour + ':' + minutes + ':' + sec
}
var p = document.getElementsByTagName('p')[0]
function setClock() {
var date = new Date(),
currentTime = date.currentTime();
p.innerText = currentTime
}
setClock()
setInterval(() => {
setClock()
}, 1000);
</script>
</body>
</html>
数字时钟-
最新推荐文章于 2024-11-12 11:19:19 发布
1586

被折叠的 条评论
为什么被折叠?



