这里是业余程序员,这个问题超出了我的工资等级.我正在try 构建一个动态html/css日历,其中单元格根据今天的日期填充.我得到了今天的日期,然后try 添加天数来填充另外13天(通过html元素.innerHTML循环).
如果我try 设置日期(30+2),然后 Select getDate().代码运行良好.Javascript计算出6月在第30天结束,结果是2(7月2日)
But this only works if there's only one call, if I have a loop, or call this code multiple times, then the result is different. Is there some async stuff gumming up the works? Here's code: If you leave the "result2" call and comment the others, works great, but multiple calls, things break and numbers get repeated. Please help!
const theDate = new Date();
const todaysDate = 30;
theDate.setDate(todaysDate + 1);
let result1 = theDate.getDate();
theDate.setDate(todaysDate + 2);
let result2 = theDate.getDate();
theDate.setDate(todaysDate + 3);
let result3 = theDate.getDate();
theDate.setDate(todaysDate + 4);
let result4 = theDate.getDate();
console.log(result1);
console.log(result2);
console.log(result3);
console.log(result4);