然后再用setTime()换成日期格式输出;
dd.setDate(dd.getDate()+AddDayCount)//获取AddDayCount天后的日期
这一句改为:
dd.setTime(dd.getTime()+AddDayCount*24*60*60*1000)//获取AddDayCount天后的日期
<input type="text" name="date" id="today" value=""/><a href="javascript:" onclick="yesterday()">昨天</a>
<a href="javascript:" onclick="tomorrow()">明天</a>
<script>
//看你引入了 jquery 所以我直接使用jquery中选择器。
$("#today").val(today(new Date()))
function today(date) {
var y = date.getFullYear()
var m = date.getMonth()+1
var d = date.getDate()
return y+"-"+m+"-"+d
}
function yesterday() {
var val = $("#today").val()
if (val){
var date = new Date(val)
date -= 24*60*60*1000
$("#today").val(today(new Date(date)))
}
}
function tomorrow() {
var val = $("#today").val()
if (val){
var date = new Date(val)
date =date.getTime()+ 24*60*60*1000
$("#today").val(today(new Date(date)))
}
}
</script>