我正在尝试通过单击 div 移动到下个月,我将月份存储为月份中的对象 = []; 但是当我使用 ++ 时,它只是在同一个月重复,为什么?这是我的 JS:
var newdate = new Date();
var getnewmonthword = newdate.getMonth();
var i = 0;
months = [];
months[0] = ('january');
months[1] = ('february');
months[2] = ('march');
months[3] = ('apri');
months[4] = ('may');
months[5] = ('june');
months[6] = ('july');
months[7] = ('august');
months[8] = ('september');
months[9] = ('october');
months[10] = ('november');
months[11] = ('december');
var countemonth = getnewmonthword;
var myMonthName = months[countemonth];
$('#test span').replaceWith('<span>' + myMonthName + '</span>')
$('#addone').on('click', function () {
alert('fred');
countemonth++;
//months[++i];
// $('#test span').replaceWith('<span>' + countemonth + '</span>')
$('#test span').replaceWith('<span>' + myMonthName + '</span>')
});
如果我取消注释 countemonth replaceWith 它实际上每个广告 1 但它只返回数字而不是名称......