jquery: using two datepicker with two fields ( field 1 , field2 + 1 day ) like booking.com

前端 未结 3 1278
离开以前
离开以前 2021-01-16 04:51

How r u?

I have two datepickers with two fields

I want when the user choosing (From) the second field ( TO ) will be next

3条回答
  •  渐次进展
    2021-01-16 05:18

    you need to convert your dateText into the right format of date, then plus one and set back to the #to value

    var from = dateText.split("-");
    var fDate = new Date(from[2], from[1] - 1, from[0]);
    
    var newdate = new Date(fDate);
    newdate.setDate(newdate.getDate() + 1);
    $("#to").val(newdate.getDate() + "-" + newdate.getMonth() + "-" + newdate.getFullYear());
    

提交回复
热议问题