After selecting the month list item, I get the Year Value and month value, and calculate the date value of the first day of the month and the last day of the month.
CorrectCodeAs follows:Copy codeThe Code is as follows: <script language = "JavaScript">
Function seldate (Y, m)
{
// Output the string No. 1 of the current month
Document. form1.startdt. value = Y + "-" + M + "-1 ";
// Calculate the year (Y) and month (m) of the next month)
If (M = 12)
{
Y ++;
M = 1;
}
Else
{
M ++;
}
// Generate the date value of January 1, 1st day of next month
VaR dt = new date (Y m-1, 1); // month value: 0--11
// The one-day difference is 86400000, which converts January 1, 1st day of next month to a value and then subtract it. The value of date on the last day of the previous month is obtained.
VaR n = date. parse (DT );
N-= 86400000;
VaR dt1 = new date (N );
// Output the date string of the last day of the current month
Document. form1.stopdt. value = dt1.getyear () + "-" + (dt1.getmonth () + 1) + "-" + dt1.getdate ();
}
</SCRIPT>
At first, I wrote "Var dt = new date (Y, S-1, 1);" as "Var dt = new date (Y, M, 1 );". The last sentence "dt1.getmonth ()" does not add 1. The result is clearly "", but the output is "", while the output is ".
At the beginning, I felt inexplicable. I tried multiple times and found the error rule. I found that the month value range is "0-11" rather than "1-12 ".
I hope this article will remind me that JS will not be used in the next time.