单击“明天”按钮时,我想获得相同的日期格式。目前它在点击时显示两种不同的输出。如果有人可以提供解决方案?下面是JS代码。
var today = new Date(),
dd = today.getDate(),
mm = today.getMonth()+1,
yyyy = today.getFullYear(),
nextDate = new Date(today.getTime() + (24 * 60 * 60 * 1000)),
tomorrow = nextDate.toDateString();
if(dd<10){
dd='0'+dd
}
if(mm<10){
mm='0'+mm
}
today = dd+'/'+mm+'/'+yyyy;
addEventListener("load", function(){
dateInput = document.getElementById('dateID');
dateInput.value = "";
}, false);
function currentDate(){
dateInput.value = today;
}
function tomorrowDate(){
dateInput.value = tomorrow;
}
/******************************
<div class="wrapper">
<input type="text" id="dateID" /><br />
<input type="button" value="Today" onclick="currentDate();" />
<input type="button" value="Tomorrow" onClick="tomorrowDate();" />
</div>