开发者

Jquery when date change, change another date

开发者 https://www.devze.com 2023-02-16 20:17 出处:网络
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?

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

0

精彩评论

暂无评论...
验证码 换一张
取 消