-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdate.html
46 lines (41 loc) · 1.14 KB
/
date.html
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<!DOCTYPE html>
<html lang="en">
<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>年龄计算器</title>
<script src="./js/jquery.min.js"></script>
<script src="./js/bootstrap.min.js"></script>
<script src="./js/dayjs.min.js"></script>
<link rel="stylesheet" href="./css/bootstrap.min.css">
<link rel="stylesheet" href="./css/vw.css">
</head>
<body class="date">
<div id="app">
<h1>年龄计算器</h1>
<div class="input-group input-group-sm">
<input type="text" class="form-control form-control-lg" />
<button type="button" class="btn btn-primary">计算</button>
</div>
<div class="jieguo">
</div>
</div>
</body>
<script>
$(document).ready(function () {
$('input').val('1995-09-18')
})
function jisuan () {
const today = dayjs().format('YYYY-MM-DD')
const old = $('input').val()
const diff = dayjs(today).diff(old, 'month')
const year = parseInt(diff / 12)
const month = diff % 12
$('.jieguo').text(`${year}年${month}月`)
}
$('.btn-primary').click(function () {
jisuan()
})
</script>
</html>