250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 자바스크립트
- effect
- IOS
- css3
- iOS 개발자
- 프론트엔드
- jQuery
- hover
- html5
- xcode
- 풀스택
- javascript
- CSS
- MAC
- HTML
- react
- Animation
- 개발자
- 비전공자
- php
- keyframes
- 비전공 개발자
- ipad
- 애니메이션
- iPhone
- SWIFT
- 백엔드
- front-end
- button
- image
Archives
- Today
- Total
비전공자 개발일기
Date Calculator 본문
728x90
SMALL
<!DOCTYPE html>
<html lang="ko">
<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>DATE CALCULATOR</title>
<link rel="stylesheet" href="style.css">
<script defer src="main.js"></script>
</head>
<body>
<header>
<h1>DATE CALCULATOR</h1>
<p>How many days are there between two dates?</p>
<p>(Change a date to automatically calculate the difference)</p>
</header>
<div>
<form action="#">
<label>Start date</label>
<input type="date" name="start_date">
<label>End date</label>
<input type="date" name="end_date">
</form>
<p>
Time elapsed:
<span class="date_span"></span>
</p>
</div>
</body>
</html>
h1 {
font-size: 2.5em;
font-weight: 700;
text-align: center;
}
header > p {
text-align: center;
font-size: 1.5rem;
font-weight: 700;
}
div {
text-align: center;
border: .1em solid #000;
}
p {
font-size: 1.4rem;
font-weight: 700;
}
body {
background-color: #000;
color: #FFF;
}
let span = document.querySelector(".date_span");
let dateInputs = document.querySelectorAll("input");
dateInputs[1].valueAsDate = new Date();
function calculateElapse() {
if(!isNaN(dateInputs[0].valueAsDate) && !isNaN(dateInputs[1].valueAsDate)) {
span.textContent = ""+((dateInputs[1].valueAsDate - dateInputs[0].valueAsDate) / (24 * 60 * 60 * 1000)) + "day(s)";
}
}
dateInputs.forEach(elements => elements.addEventListener("change", calculateElapse));
728x90
LIST
'Javascript' 카테고리의 다른 글
Word Counter (0) | 2022.06.20 |
---|---|
Background color picker (0) | 2022.06.18 |
Javascript Modal Popup Box (0) | 2022.06.07 |
Create Date Time Day (0) | 2022.05.31 |
Download Button Animation (0) | 2022.05.25 |