
index.html
<!DOCTYPE html>
<html>
<head>
<title>Something</title>
<link rel="stylesheet" href="index.css"/>
</head>
<body>
<div class="js-clock">
<h1>00:00</h1>
</div>
<script src="clock.js"></script>
</body>
</html>
clock.js
const clockContainer = document.querySelector(".js-clock"),
clockTitle=clockContainer.querySelector("h1");
function getTime(){
const date =new Date();
const minutes=date.getMinutes();
const hours=date.getHours();
const seconts=date.getSeconds();
clockTitle.innerText=`${
hours< 10 ? `0${hours}`:hours}:${
minutes< 10? `0${minutes}`:minutes}:${
seconts< 10 ?`0${seconts}`:seconts}`;
}
function init(){
getTime();
setInterval(getTime,1000);
}
init();
'vanila.js' 카테고리의 다른 글
| js에서 리스트저장 (0) | 2020.12.02 |
|---|---|
| function (0) | 2020.11.26 |
| 변수 (0) | 2020.11.25 |