This is done after the effect. Not very beautiful, but also can be further improved.
The HTML+CSS code is as follows:
<! DOCTYPE html>
The JavaScript code is as follows:
var nowdate=new Date (), Var nowyear=nowdate.getfullyear (), Var nowmonth=nowdate.getmonth () +1;//var month= (nowMonth <10? " 0 "+momth:month); var Text=document.getelementbyid (" Yearandmon "); text.innertext=nowyear+" year "+nowmonth+" month "; var MONTHDAYS1=[31,29,31,30,31,30,31,31,30,31,30,31]; var monthdays2=[31,28,31,30,31,30,31,31,30,31,30,31]function becomedate (nowyear,nowmonth) {var dt=new Date (NowYear, nowmonth-1,1) var firstday=dt.getday () var Table=document.getelementbyid ("table1"); var Monthdays=isrunnian () var Rows=5;var Cols=7;var K=1;for (var i=1;i<=rows;i++) {var tri=table.insertrow (); for (Var j=1;j<=7;j++) {var tdi= Tri.insertcell (); if (i==1&&i*j<firstday+1) tdi.innerhtml= ""; Else{if (K>monthdays[nowmonth-1]) break; tdi.innerhtml=k;k++;}}}} function Lastmon () {table1.innerhtml= ""; var Text=document.getelementbyid ("Yearandmon"); if (nowmonth>1) nowMonth= nowmonth-1;else{nowyear--;nowmonth=12;} text.innertext=nowyear+ "Year" +nowmonth+ "month"; Becomedate (Nowyear,nowmonth);} function Nextmon () {table1.innerhtml= ""; if (nowmonth<12) nowmonth=nowmonth+1;else{nowyear++;nowmonth=1;} var Text=document.getelementbyid ("Yearandmon"), text.innertext=nowyear+ "year" +nowmonth+ "month"; Becomedate (NowYear, Nowmonth);} function Isrunnian () {if (nowyear%4==0| | nowyear%400==0) &&nowyear%100!=0) return Monthdays1;elsereturn MonthDays2;} Becomedate (Nowyear,nowmonth);
There are many shortcomings in the code, please advise.
Make a calendar with Html+css+javascript