//------[获取两个日期中所有的月份中]
function getMonthBetween(start,end){
var result = [];
var s = start.split("-");
var e = end.split("-");
var min = new Date();
var max = new Date();
min.setFullYear(s[0],s[1]);
max.setFullYear(e[0],e[1]);
console.log(e[0]+"---- "+e[1]);
var curr = min;
while(curr <= max){
var month = curr.getMonth();
//month=month==0?12:month;
console.log(month);
var str=curr.getFullYear()+"-"+(month);
var s=curr.getFullYear()+"-0";
if(str==s){
str=curr.getFullYear()+"-12";
}
result.push(str);
curr.setMonth(month+1);
}
return result;
}
//------[获取两个日期中所有的月份中END]
html
<script>
console.log(getMonthBetween('2017-7', '2018-2'));
</script>
效果图