在datepicker中添加几天到minDate

时间:2012-04-05 15:03:51

标签: jquery-ui datepicker mindate

如何更改此代码

minDate:'2012/3/4'+'5D',

var dates = $( "#from, #to" ).datepicker({
    dateFormat: 'yy/mm/dd',
    changeMonth: true,

    **minDate: '2012/3/4'+'5D',**

    onSelect: function() { 
       var d1=new Date($('#from').val());
       var d2=new Date($('#to').val());
       $('#quantity').val((Math.ceil((d2-d1)/86400000)));
   }
}); 

到最小日期be => 2012/3/9

罐中。

1 个答案:

答案 0 :(得分:0)

免责声明:如果它实际上是硬编码的,只需将其更改为'2012/3/9'

解析日期,添加5天,然后再将其转换为字符串:

var d = '2012/3/4';
var parts = d.split('/');
var date = new Date(+parts[0], +parts[1] - 1, +parts[2]);

date.setDate(date.getDate() + 5);

var result = date.getFullYear() + '/' + (date.getMonth() + 1) + '/' + date.getDate();

Here's a demo.

这里放在你的代码中:

var d = '2012/3/4';
var parts = d.split('/');
var date = new Date(+parts[0], +parts[1] - 1, +parts[2]);

date.setDate(date.getDate() + 5);

var result = date.getFullYear() + '/' + (date.getMonth() + 1) + '/' + date.getDate();

var dates = $( "#from, #to" ).datepicker({
    dateFormat: 'yy/mm/dd',
    changeMonth: true,
    minDate: result,
    onSelect: function() { 
       var d1=new Date($('#from').val());
       var d2=new Date($('#to').val());
       $('#quantity').val((Math.ceil((d2-d1)/86400000)));
    }
});