让我们分解一下:
var d = new Date(); // date is now 2013-01-31d.setMonth(1); // date is now 2013-02-31, which is 3 days past 2013-02-28x = d.getMonth(); // what to do, what to do, 3 days past 2013-02-28 is in March // so, expect x to be March, which is 2
只有当天的值
d大于传递给的当月的最大天数时,这才是问题
setMonth()。否则,它会按您期望的那样工作。



