获取每个月递减的算法
function lastMonth() {
var dt = document.getElementById("d1").innerText;
var strArr = dt.split('-');
var year = strArr[0];
var month = strArr[1];
var day = strArr[2];
//一月的时候回到上一年的12月
if (strArr[1] == 1) {
year = year - 1;
month = 12;
}
else {
month = month - 1;
}
if (month.toString().length == 1) {
month = '0' + month;
}
document.getElementById("d1").innerText = year + '-' + month + '-' + day;
}
var dt = document.getElementById("d1").innerText;
var strArr = dt.split('-');
var year = strArr[0];
var month = strArr[1];
var day = strArr[2];
//一月的时候回到上一年的12月
if (strArr[1] == 1) {
year = year - 1;
month = 12;
}
else {
month = month - 1;
}
if (month.toString().length == 1) {
month = '0' + month;
}
document.getElementById("d1").innerText = year + '-' + month + '-' + day;
}