任何人都可以看到我出错的地方吗?
today = new Date();
expo = new Date("February 05, 2012");
msPerDay = 24 * 60 * 60 * 1000 ;
timeLeft = (expo.getTime() - today.getTime());
e_daysLeft = timeLeft / msPerDay;
daysLeft = Math.floor(e_daysLeft);
document.getElementById('cdown').innerHTML = document.write(daysLeft);
答案 0 :(得分:7)
document.getElementById('cdown').innerHTML = daysLeft
您不需要document.write
答案 1 :(得分:2)
请勿使用document.write(daysLeft)
,这会将daysLeft
写入文档,而不是div
!只需设置daysLeft
:
document.getElementById('cdown').innerHTML = daysLeft;
答案 2 :(得分:2)
在这一行:
document.getElementById('cdown').innerHTML = document.write(daysLeft);
删除document.write(
。如果您正在设置元素的内容,则也不需要写入文档。
固定代码:
today = new Date();
expo = new Date("February 05, 2012");
msPerDay = 24 * 60 * 60 * 1000 ;
timeLeft = (expo.getTime() - today.getTime());
e_daysLeft = timeLeft / msPerDay;
daysLeft = Math.floor(e_daysLeft);
document.getElementById('cdown').innerHTML = daysLeft;