下面代碼實際測試是沒有問題的。
$("#date").click(function () {
var temp = new Date(2018,7,7);
alert(temp);
// 原來是2018年8月7日,加6個月后應該是2019年2月7日
temp.setMonth(temp.getMonth() + 1 + 6);//由於設計缺陷,要在設置月份的時候就加1
alert(temp.getFullYear());// 2019
alert(temp.getMonth());// 2
alert(temp.getDate());// 7
});