知識點介紹:
1、介紹我的工具包
2、運用JavaScript內建物件Date
先來看看運行效果:
如圖:
(推薦教學: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('load',function (ev) { setInterval(function () { myTool.$('year').innerText = myTool.getTime().year; myTool.$('month').innerText = myTool.getTime().month < 10 ? '0' + myTool.getTime().month : myTool.getTime().month; myTool.$('day').innerText = myTool.getTime().day < 10 ? '0' + myTool.getTime().day : myTool.getTime().day; myTool.$('week').innerText = myTool.getTime().week ; myTool.$('hour').innerText = myTool.getTime().hour < 10 ? '0' + myTool.getTime().hour : myTool.getTime().hour; myTool.$('minute').innerText = myTool.getTime().minute < 10 ? '0' + myTool.getTime().minute : myTool.getTime().minute; myTool.$('second').innerText = myTool.getTime().second < 10 ? '0' + myTool.getTime().second : myTool.getTime().second; },1000); },false); </script> </body> </html>
更多酷炫CSS3、html5、javascript特效程式碼,盡在:js特效大全
以上是如何使用js實作簡單日曆效果的詳細內容。更多資訊請關注PHP中文網其他相關文章!