javascript 模拟日历
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <title>Document</title>
6 <style>
7 div {
8 width: 800px;
9 margin: 200px auto;
10 color: orange;
11 text-align: center;
12 font: 600 30px/30px "simSun";
13 }
14 </style>
15 </head>
16 <body>
17 <div></div>
18
19 <script>
20 //模拟日历需求:每天打开页面都能定时显示年月日和星期几
21 //步骤:创建一个当前日期的日期对象,获取其中的年月日和星期,赋值给div
22
23 //1.创建一个当前日期的日期对象
24 var date = new Date();
25 //2.获取其中的年月日和星期
26 var year = date.getFullYear();
27 var month = date.getMonth();
28 var day = date.getDate();
29 var week = date.getDay();
30 // console.log(year+" "+month+" "+day+" "+week);
31 //3.赋值给div
32 var arr =["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
33 var div = document.getElementsByTagName("div")[0];
34 div.innerText = "今天是:"+year+"年"+(month+1)+"月"+day+"日"+arr[week];
35 </script>
36 </body>
37 </html>
本文来自博客园,作者:叶子玉,转载请注明原文链接:https://www.cnblogs.com/knuzy/p/8836206.html