Jquery Mobile Datepicker 在滑动时更改月份 [英] Jquery Mobile Datepicker change month on swipe
本文介绍了Jquery Mobile Datepicker 在滑动时更改月份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在滑动时更改日期选择器的月份?我的意思是有什么方法可以在滑动时显示下个月和上个月?
is there a way to change the datepicker's month on swipe? I mean any way to display next and previous month on swipe?
这是我的方法:
Jquery 移动滑动:
Jquery Mobile Swipe:
// 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 datePicker 代码:
And Here is Jquery Mobile datePicker Code:
$(".date-input-inline").datepicker({
onChangeMonthYear: function(year, month, inst) {
$(".ui-datepicker").fadeOut(0);
$(".ui-datepicker").fadeIn("normal");
},
dateFormat: 'yy-mm-dd',
yearRange: currentY + ':' + currentY,
});
推荐答案
使用getDate
方法获取日期,添加月份然后使用setDate
设置设置新日期的方法.
use the getDate
method to get the date, add a month and then set the using the setDate
method to set the new date.
这是向右滑动的示例:
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
向左滑动会有相同类型的代码,你只需要减去一个月.
swipe left would have same type of code, you just need to subtract a month.
这篇关于Jquery Mobile Datepicker 在滑动时更改月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文