When I select the month list item, I get the year value and the month value to calculate the date value of the month 1th and the last day of the month.
The correct code is as follows:
Copy Code code as follows:
<script language= "JavaScript" >
function Seldate (y, M)
{
Output string for the month, 1th
document.form1.startdt.value=y+ "-" +m+ "-1";
Calculates the year (Y), month value (m) of the next month
if (m==12)
{
y++;
M=1;
}
Else
{
m++;
}
Generate date value for 1st of next month
var dt=new Date (Y, m-1, 1); Month Value 0--11
Day difference = 86400000, convert next month 1st to a numeric value, then subtract, last month date value
var n=date.parse (DT);
N-= 86400000;
var dt1=new Date (n);
Output date string for the last day of the month
Document.form1.stopdt.value=dt1.getyear () + "-" + (Dt1.getmonth () +1) + "-" +dt1.getdate ();
}
</script>
I'll start with "var dt=new Date (Y, m-1, 1);" Written "Var dt=new Date (Y, M, 1);". And the last sentence "Dt1.getmonth ()" did not add 1. The result can be imagined, obviously is "2010-2-28", the output is "2010-1-28", and "2010-1-31" Output is "2010-0-31".
Just beginning to feel puzzled, tried, found the error law, found that the month range is "0-11" instead of "1-12".
Hope that the next period of time after the use of JS, this article can remind me.