美文网首页
2018-07-30简易时钟

2018-07-30简易时钟

作者: 菜鸟亿个 | 来源:发表于2018-07-30 11:40 被阅读0次

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>简易时钟</title>
</head>
<body>
<h2>当前时间</h2>

<script>
/**
* 当前时间 hh:mm:ss 9:01:15
*/
function currentTime() {
var day = new Date();
var hours = day.getHours(); //小时
var minutes = day.getMinutes(); //分钟
var seconds = day.getSeconds(); //秒

    var currentDay = hours + ":" + minutes + ":" + seconds;
    pElement.style.color = "red";  //改变元素样式
    pElement.innerHTML = currentDay;  //改变元素内容
}
var bodyElement = document.getElementsByTagName("body")[0];  //获取元素
var pElement = document.createElement("p");   //创建元素
bodyElement.appendChild(pElement);  //添加元素
window.setInterval("currentTime()",1000);

</script>
</body>

相关文章

网友评论

      本文标题:2018-07-30简易时钟

      本文链接:https://www.haomeiwen.com/subject/ovaxvftx.html