【发布时间】:2015-11-29 18:31:18
【问题描述】:
有人可以帮我理解为什么这在地球上不起作用?
document.write('messing with the dates: <br>')
var nowDate = new Date();
var currentDay = nowDate.getDate();
nowDate.setDate(currentDay + 1);
document.write('if it\'s not inside a variable, it\'s nice and tidy: ' + nowDate.getDate() + '<br>');
var tomorrow = (nowDate.setDate(currentDay + 1));
document.write('but as soon as I put it inside a var, it becomes terrible: ' + tomorrow);
document.write('and this is not even working' + tomorrow.getDate());
【问题讨论】:
-
什么“不起作用”?你期待发生什么?实际发生了什么?
-
var tomorrow = (nowDate.setDate(currentDay + 1));不等于var tomorrow = nowDate.getDate()为什么不使用后者?看来这就是你想要的。 -
我没有使用 getDate() 因为我已经知道日期,我想修改日期。
-
这很好用:
nowDate.setDate(currentDay + 1); document.write(nowDate.getDate());这不行:var tomorrow = nowDate.setDate(currentDay + 1); document.write( tomorrow);这是问题所在,我不明白为什么。
标签: javascript date var getdate