我的jQuery函数需要current month
。我想根据点击的按钮显示下个月和上个月。使用jQuery查找下个月和上个月
我的问题是,有没有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());
});
http://momentjs.com/ – CodingIntrigue