如何使用jquery datepicker向日期添加一天 [英] how to add a day to a date using jquery datepicker

查看:46
本文介绍了如何使用jquery datepicker向日期添加一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上有 2 个文本框,用于使用 jquery 日期选择器指定取货日期和还车日期.

I have 2 textboxes on my site for pickup date and drop off date both using the jquery date picker.

我无法将还车日期值设置为比所选取件日期早一天.

I am having trouble setting the drop off date value to be one day ahead of the pickup date that was selected.

这是我所拥有的:

$('.pickupDate').change(function() {
    var date2 = $('.pickupDate').datepicker('getDate', '+1d'); 
    $('.dropoffDate').datepicker('setDate', date2);
});

以上将执行,但还车文本框中的值将与取件值匹配,而不是提前一天.例如:如果我选择 01-01-2010,上面的代码会在下拉框中返回 01-01-2010 而不是 02-01-2010.

The above will execute but the value in the drop off textbox will match the pickup value instead of being one day ahead. eg: if I select 01-01-2010 the above code returns 01-01-2010 in the drop off box instead of 02-01-2010.

有什么想法吗?

感谢您的帮助,丰富的

推荐答案

试试这个:

 $('.pickupDate').change(function() {
  var date2 = $('.pickupDate').datepicker('getDate', '+1d'); 
  date2.setDate(date2.getDate()+1); 
  $('.dropoffDate').datepicker('setDate', date2);
});

这篇关于如何使用jquery datepicker向日期添加一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆