2014-06-27 39 views
3

有没有办法在刷卡时更改日期选择器的月份?我的意思是任何方式来显示下一个和上个月刷卡?Jquery Mobile Datepicker在刷卡上更改月份

这里是我的方法:

jQuery Mobile的刷卡:

// Bind the swipeHandler callback function to the swipe event on div.box 
$("#main-page").on("swipeleft", swipeLeftHandler).on("swiperight", swipeRightHandler); 

function swipeLeftHandler(event){ 
// $(event.target).addClass("swipe"); 
    console.log('swiped Left'); 
} 

function swipeRightHandler(event){ 
// $(event.target).addClass("swipe"); 
    console.log('swiped Right'); 
} 

,这里是jQuery Mobile的日期选择器代码:

$(".date-input-inline").datepicker({ 
    onChangeMonthYear: function(year, month, inst) { 

     $(".ui-datepicker").fadeOut(0); 

     $(".ui-datepicker").fadeIn("normal"); 

    }, 
    dateFormat: 'yy-mm-dd', 
    yearRange: currentY + ':' + currentY, 
}); 

回答

1

使用getDate方法来获得日期,加月,然后使用setDate方法设置新日期。

这里的刷卡权的例子:

var thedate=$(".date-input-inline").datepicker('getDate'); //get date from datepicker 
thedate.setMonth(thedate.getMonth()+1); //add a month 
$(".date-input-inline").datepicker('setDate',thedate); // set the date in datepicker 

向左滑动,将有相同类型的代码,你只需要一个月的时间中减去。

相关问题