Jquery Mobile Datepicker更改月份刷卡 [英] Jquery Mobile Datepicker change month on swipe
本文介绍了Jquery Mobile Datepicker更改月份刷卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的方法:
Jquery Mobile滑动:
//将swipeHandler回调函数绑定到div.box上的滑动事件
$(#main p).on(swipeleft,swipeLeftHandler).on(swiperight,swipeRightHandler);
函数swipeLeftHandler(event){
// $(event.target).addClass(swipe);
console.log('swiped Left');
}
函数swipeRightHandler(event){
// $(event.target).addClass(swipe);
console.log('swiped Right');
}
这里是Jquery Mobile datePicker代码:
$(。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
方法设置新日期。
这里是滑动右侧的示例:
var thedate = $(。date-input-inline ).datepicker('getDate'); //从datepicker获取日期
thedate.setMonth(thedate.getMonth()+ 1); //添加一个月
$(。date-input-inline)。datepicker('setDate',thedate); //在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?
Here is my approach:
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');
}
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,
});
解决方案
use the getDate
method to get the date, add a month and then set the using the setDate
method to set the new date.
here's the example for the swipe right:
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屋!
查看全文