代码:

 
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
 
<input type="date" id="d" value="2018-10-01">
<button onclick="getDate()">点我</button>
<p id="demo"></p>
<script>
function getDate() {
    var s1 = document.getElementById("d").value;
    s1 = new Date(s1.replace(/-/g, "/"));
    s2 = new Date();
    var days = s2.getTime() - s1.getTime();
    var time = parseInt(days / (1000 * 60 * 60 * 24));
    document.getElementById("demo").innerHTML = '天数:'+time;
}
</script>
 
</body>
</html>
 

 

posted on 2019-04-01 15:06  月零Ray  阅读(409)  评论(0编辑  收藏  举报