一、前端JS
$(function(){
$('#startDate').datebox('setValue', getStartdate());
$('#endDate').datebox('setValue', getEnddate());
});
二、后台代码
function getEnddate(){
var myDate = new Date();
var nowY = myDate.getFullYear();
var nowM = myDate.getMonth()+1;
var nowD = myDate.getDate();
var enddate = nowY+"-"+(nowM<10 ? "0" + nowM : nowM)+"-"+(nowD<10 ? "0"+ nowD : nowD);
return enddate;
}
function getStartdate(){
var myDate = new Date();
var lw = new Date(myDate - 1000 * 60 * 60 * 24 * 30);//最后一个数字30可改,30天的意思
var lastY = lw.getFullYear();
var lastM = lw.getMonth()+1;
var lastD = lw.getDate();
var startdate=lastY+"-"+(lastM<10 ? "0" + lastM : lastM)+"-"+(lastD<10 ? "0"+ lastD : lastD);
return startdate;
}
三、展示效果