I use a Jquery date-picker for a start and end date, what I would like to do is when the user changes the 'start' date, the 'end' date automatically changes to the start date + X days?
What w开发者_Python百科ould others suggest the best way of doing this? I am using GB dates so its dd/mm/yyyy
so doesn't work out of the box with the JavaScript date object? am sure this is trivial for a more experienced jQuery folk!
You'll want to bind to the onSelect
event. See the jQuery docs for it here.
This is probably about what you're looking for.
var DAYS = 6; // <-- Or whatever
$('#start_date').datepicker({
onSelect: function(dateText, inst) {
$('#end_date').setDate(
(Number(dateText.substr(0,2))+DAYS) + dateText.substr(2)
)
},
dateFormat: 'dd/mm/yy',
});
$('#end_date').datepicker({
dateFormat: 'dd/mm/yy',
});
There is an event in the jquery UI Date picker.
Please have a look to: http://jqueryui.com/demos/datepicker/#event-onSelect
精彩评论