Home > front end >  In the table have a problem
In the table have a problem

Time:09-18


Should be how to fill the empty place in
 & lt; ! DOCTYPE html> 


<meta charset="utf-8" & gt;

<style type="text/CSS" & gt;
# nianli {
Width: 880 px;
Margin: 0 px auto;
The text - align: center;
The font-family: "tahoma";

}

Th {
Background - color: cyan.
Color: royalblue;
}

Table {
width:200px;
height:200px;
margin:10px;
float:left;
Border: # 1 px solid aa5500;

}

Td: first - child, td: last child {
-color:red;
}

</style>
Var year=prompt (" please enter the year: ", "2020");
Document. The write (getnianli (year));
The function getnianli (y) {
Var HTM="";
HTM +='& lt; Div id="nianli" & gt; ';
For (var m=1; M & lt;=12; M++) {
HTM +='& lt; Table> ';
HTM +='& lt; tr> ';
HTM +='& lt; tr> Day & lt;/td> A & lt;/td> 2 & lt;/td> Three & lt;/td> Four & lt;/td> Five & lt;/td> Six & lt;/td> ';
HTM +='& lt; tr> ';
Var firstday=new Date (y, m - 1, 1). GetDay ();
Var Max=new Date (y, m, 0). The getDate ();
for (var i=0; I & lt; The firstday; I++) {
HTM +='& lt; td> ';
}
For (var d=1; D & lt;=Max; D++) {
HTM +='& lt; td> '+ d + & lt;/td> ';
If (((d + firstday) % 7==0) & amp; & d !=Max) {
HTM +='& lt;/tr> ';
}
Else if (d==Max) {
Var endday=7 - (Max + firstday) % 7;
for (var i=0; I & lt; Endday; I++) {
HTM +='& lt; td> ';
}
HTM +='& lt;/tr> '
}
}
HTM +='& lt;/table> ';
}
HTM +='& lt;/div> '
Return the HTM.
}
</script>

<body>

CodePudding user response:

 
Var year=prompt (" please enter the year: ", "2020");
Document. The write (getnianli (year));
The function getnianli (y) {
Var HTM="";
HTM +='& lt; Div id="nianli" & gt; ';
For (var m=1; M & lt;=12; M++) {
HTM +='& lt; Table> ';
HTM +='& lt; tr> ';
HTM +='& lt; tr> Day & lt;/td> A & lt;/td> 2 & lt;/td> Three & lt;/td> Four & lt;/td> Five & lt;/td> Six & lt;/td> ';
HTM +='& lt; tr> ';
Var firstday=new Date (y, m - 1, 1). GetDay ();
Var Max=new Date (y, m, 0). The getDate ();
for (var i=0; I & lt; The firstday; I++) {
HTM +='& lt; td> ';
}
For (var d=1; D & lt;=Max; D++) {
HTM +='& lt; td> '+ d + & lt;/td> ';
If (((d + firstday) % 7==0) & amp; & d !=Max) {
HTM +='& lt;/tr> ';
}
}
Var endday=(70 - Max - firstday) % 7;
for (var i=0; I & lt; Endday; I++) {
HTM +='& lt; td> ';
}
HTM +='& lt;/tr> ';
HTM +='& lt;/table> ';
}
HTM +='& lt;/div> '
Return the HTM.
}
  • Related