Rumah  >  Artikel  >  hujung hadapan web  >  如何使用js实现简单日历效果

如何使用js实现简单日历效果

王林
王林ke hadapan
2020-03-30 09:28:242507semak imbas

如何使用js实现简单日历效果

知识点介绍:

1、引入我的工具包

2、运用JavaScript内置对象 Date

先来看一下运行效果:

如图:

dca4f55b9bf4d02b02d03b358081fa2.png

(推荐教程:js教程

直接上代码:

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Title</title>
 <style>
  *{
   margin: 0;
   padding: 0;
  }
  #box{
   width: 250px;
   height: 300px;
   background-color: orangered;
   margin: 100px auto;
   padding: 30px;
  }
  #box_top{
   font-size: 22px;
   color: #fff;
   margin-bottom: 40px;
   display: flex;
   justify-content: space-around;
  }
  #box_bottom{
   width: 90%;
   height: 70%;
   margin: 0 auto;
   background-color: orange;
   font-size: 50px;
   color:#fff;
   display: flex;
   justify-content: center;
   align-items: center;
  }
 </style>
</head>
<body>
 <div id="box">
  <div id="box_top">
   <span id="year"></span>
   <span>年</span>
   <span id="month"></span>
   <span>月</span>
   <span id="day"></span>
   <span>日</span>
   <span id="week"></span>
  </div>
  <div id="box_bottom">
   <span id="hour"></span>
   <span>:</span>
   <span id="minute"></span>
   <span>:</span>
   <span id="second"></span>
  </div>
 </div>
 <script src="../../MyTools/MyTools.js"></script>
 <script>
  window.addEventListener(&#39;load&#39;,function (ev) {
   setInterval(function () {
    myTool.$(&#39;year&#39;).innerText = myTool.getTime().year;
    myTool.$(&#39;month&#39;).innerText = myTool.getTime().month < 10 ? &#39;0&#39; + myTool.getTime().month : myTool.getTime().month;
    myTool.$(&#39;day&#39;).innerText = myTool.getTime().day < 10 ? &#39;0&#39; + myTool.getTime().day : myTool.getTime().day;
    myTool.$(&#39;week&#39;).innerText = myTool.getTime().week ;
    myTool.$(&#39;hour&#39;).innerText = myTool.getTime().hour < 10 ? &#39;0&#39; + myTool.getTime().hour : myTool.getTime().hour;
    myTool.$(&#39;minute&#39;).innerText = myTool.getTime().minute < 10 ? &#39;0&#39; + myTool.getTime().minute : myTool.getTime().minute;
    myTool.$(&#39;second&#39;).innerText = myTool.getTime().second < 10 ? &#39;0&#39; + myTool.getTime().second : myTool.getTime().second;
   },1000);
 
  },false);
 </script>
</body>
</html>

更多炫酷CSS3、html5、javascript特效代码,尽在:js特效大全

Atas ialah kandungan terperinci 如何使用js实现简单日历效果. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan:
Artikel ini dikembalikan pada:jb51.net. Jika ada pelanggaran, sila hubungi admin@php.cn Padam