我的 jQuery 函数采用current month
. 我想根据单击的按钮显示下个月和上个月。
我的问题是,default
Date()
我可以调用一个函数来了解当前月份的下个月和上个月吗?
$(document).ready(function () {
var current_date = $('#cal-current-month').html();
//current_date will have September 2013
$('#previous-month').onclick(function(){
// Do something to get the previous month
});
$('#next-month').onclick(function(){
// Do something to get the previous month
});
});
我可以编写一些代码并获得下个月和前几个月,但我想知道是否已经有任何defined functions
用于此目的的代码?
解决了
var current_date = $('.now').html();
var now = new Date(current_date);
var months = new Array( "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
$('#previous-month').click(function(){
var past = now.setMonth(now.getMonth() -1);
$('.now').html(months[now.getMonth()]+' '+now.getFullYear());
});
$('#next-month').click(function(){
var future = now.setMonth(now.getMonth() +1);
$('.now').html(months[now.getMonth()]+' '+now.getFullYear());
});