Add a day with selected date using Jquery datepicker

只愿长相守 提交于 2019-12-01 02:56:59

问题


I have been trying to add a day for another date field with date selected of current field

     ,
 onSelect: function(date) {
     var date2 = $('.currDate').datepicker('getDate');
       date2.setDate(date2.getDate()+1); 
       $('.nextDt').datepicker('setDate', date2);
    }

However I am getting at date2.setDate(date2.getDate()+1);

Message: Object doesn't support this property or method

How can I solve this issue?


回答1:


It is because, currDate might be empty.

If currDate is emtpy $('.currDate').datepicker('getDate') will return null in which case date2.setDate(date2.getDate()+1); could throw the error

Update:

$(function() {
    $('#nxtDate').datepicker({
        dateFormat: "dd-M-yy", 
    });
    $("#currDate").datepicker({
        dateFormat: "dd-M-yy", 
        minDate:  0,
        onSelect: function(date){
            var date2 = $('#currDate').datepicker('getDate');
            date2.setDate(date2.getDate()+1);
            $('#nxtDate').datepicker('setDate', date2);
        }
    });
})



回答2:


setDate and getDate are the functions supported by Date() of js while you getDate from datepicker it returns as string so you need to convert it or try this code:

onSelect: function(date) {  
     if(date!=undefined){
         var dateObject=new Date(date);
         dateObject.setDate(dateObject.getDate()+1);                                 
         $('.nextDt').datepicker('setDate', dateObject);
      }
    }

Here is Demo Alerting Current and Next Date




回答3:


echo date('d-m-Y', strtotime("+".$nod." days"));

nod= Number of days



来源:https://stackoverflow.com/questions/16117718/add-a-day-with-selected-date-using-jquery-datepicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!