Magum Opus

<!DOCTYPE html>
<html lang="kr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>날짜계산기</title>
<script>
var today = new Date().getTime();
var soloday = function(){
var birth = document.getElementsByTagName("input")[0].value;
var year = birth.split("-")[0];
var month = birth.split("-")[1];
var day = birth.split("-")[2];

var birthDay = new Date( year, month-1, day).getTime()
var time = today-birthDay
var sDay = Math.ceil(time/(1000*60*60*24));
document.getElementsByClassName("text")[0].innerHTML = "모솔" + "<span>"+sDay+"</span>" + "일차..."
}
</script>
<style>
#box{margin:0 auto;width:300px;height:200px;}
#box input{width:100px;height:30px;font-size:16px;}
#box .text{font-size:18px;}
#box span{font-style:bold;color:#f00}
</style>
</head>
<body>
<div id="box">
<input type="text" value="1996-12-10" /> <button class="btn" onclick="soloday()">입력</button>
<p class="text"></p>
</div>
</body>
</html>


' > javascript' 카테고리의 다른 글

띠 구하기  (0) 2018.01.03
노드를 클릭할때마다 클래스를 토글시키는법  (0) 2017.12.11
2017.11.29  (0) 2017.11.29