我有一个javascript代码,看起来像这样
var startdate = "06/10/2014";
//var newdate = new Date();
var num = 12
var months = [];
for (var a = 0; a < num; a++) {
var dt = new Date(startdate);
dt.setMonth(dt.getMonth() - a);
months[a] = dt;
}
return months;
arylist = arylist + '{';
arylist = arylist + '"name" :"' + months + '",';
arylist = arylist + '"st_time_am_pm" :"' + st_time_am_pm + '",';
arylist = arylist + '"ed_time_am_pm" :"' + ed_time_am_pm + '",';
arylist = arylist + '}]';
for循环返回基于插入日期返回12个月的相同数据。我想在'"name" :"' + months + '",
显示所有结果,它会在arrylist中显示。但它只是通过那部分。我不知道问题出在哪里。任何帮助赞赏。感谢
答案 0 :(得分:0)
试试这个:
var startdate = "06/10/2014";
//var newdate = new Date();
var num = 12
var months = [];
var dt = new Date(startdate);
for (var a = 0; a < num; a++) {
dt.setMonth(dt.getMonth() - a);
months[a] = dt;
}
arylist = arylist + '{';
arylist = arylist + '"name" :"' + months + '",';
arylist = arylist + '"st_time_am_pm" :"' + st_time_am_pm + '",';
arylist = arylist + '"ed_time_am_pm" :"' + ed_time_am_pm + '",';
arylist = arylist + '}]';
return months;