<!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>