使用 Jquery datepicker 添加具有选定日期的一天

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16117718/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 16:28:34  来源:igfitidea点击:

Add a day with selected date using Jquery datepicker

jquerydatepickerjquery-ui-datepicker

提问by J?cob

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);

但是我正在 date2.setDate(date2.getDate()+1);

Message: Object doesn't support this property or method

How can I solve this issue?

我该如何解决这个问题?

回答by Arun P Johny

It is because, currDatemight be empty.

这是因为,currDate可能是空的。

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

如果currDate是 emtpy$('.currDate').datepicker('getDate')将返回,null在这种情况下 date2.setDate(date2.getDate()+1);可能会抛出错误

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);
        }
    });
})

回答by Zaheer Ahmed

setDateand getDateare 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:

setDate并且getDateDate()js支持的函数,当您从 datepicker 获取日期时,它以字符串形式返回,因此您需要对其进行转换或尝试以下代码:

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

这是演示警报当前和下一个日期

回答by Uttam Swamy

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

nod= Number of days

点头=天数