Javascript 如何在jquery日历上添加一天

Javascript 如何在jquery日历上添加一天,javascript,jquery,date,Javascript,Jquery,Date,我正在使用这段代码在我的页面上创建jquery日历 $(function(){ //set the datepicker var dateToday = new Date(); $('#pikdate').datetimepicker({ minDate: dateToday, dateFormat: 'dd/mm/yy', defaultDate: '+1w' }); }); 如何在此日历中

我正在使用这段代码在我的页面上创建jquery日历

$(function(){
    //set the datepicker
    var dateToday = new Date();
    $('#pikdate').datetimepicker({       
        minDate: dateToday,
        dateFormat: 'dd/mm/yy',
        defaultDate: '+1w'
    });   
}); 
如何在此日历中添加日历应在24小时后开始的日期。

您可以这样做

$('#pikdate').datepicker({       
      minDate: dateToday,
      dateFormat: 'dd/mm/yy',
      defaultDate: '+1w'
});   

您可以在设置为“minDate”的日期中添加一天。 请参见此处的示例(我更改了您的代码):

但是要使“addDays”函数工作,您必须创建下面所示的函数

我总是创建7个函数来处理JS中的日期:addSeconds、addMinutes、addHours、addDays、addWeeks、addMonths、addYears

您可以在此处看到一个示例:

以下是功能:

        Date.prototype.addSeconds = function(seconds) {
            this.setSeconds(this.getSeconds() + seconds);
            return this;
        };

        Date.prototype.addMinutes = function(minutes) {
            this.setMinutes(this.getMinutes() + minutes);
            return this;
        };

        Date.prototype.addHours = function(hours) {
            this.setHours(this.getHours() + hours);
            return this;
        };

        Date.prototype.addDays = function(days) {
            this.setDate(this.getDate() + days);
            return this;
        };

        Date.prototype.addWeeks = function(weeks) {
            this.addDays(weeks*7);
            return this;
        };

        Date.prototype.addMonths = function (months) {
            var dt = this.getDate();

            this.setMonth(this.getMonth() + months);
            var currDt = this.getDate();

            if (dt !== currDt) {  
                this.addDays(-currDt);
            }

            return this;
        };

        Date.prototype.addYears = function(years) {
            var dt = this.getDate();

            this.setFullYear(this.getFullYear() + years);

            var currDt = this.getDate();

            if (dt !== currDt) {  
                this.addDays(-currDt);
            }

            return this;
        };

它们是propotype函数,这意味着“Date”类型中的每个变量都有此函数。

您使用的是哪个日期选择器插件?jQuery UI Datepicker 1.9.2Hi@AnkurSinghal我回答了您的问题,请告诉我它是否适用于您。:)我也在用这个,但我也需要一个时间,这就是为什么我用datetimepicker
        Date.prototype.addSeconds = function(seconds) {
            this.setSeconds(this.getSeconds() + seconds);
            return this;
        };

        Date.prototype.addMinutes = function(minutes) {
            this.setMinutes(this.getMinutes() + minutes);
            return this;
        };

        Date.prototype.addHours = function(hours) {
            this.setHours(this.getHours() + hours);
            return this;
        };

        Date.prototype.addDays = function(days) {
            this.setDate(this.getDate() + days);
            return this;
        };

        Date.prototype.addWeeks = function(weeks) {
            this.addDays(weeks*7);
            return this;
        };

        Date.prototype.addMonths = function (months) {
            var dt = this.getDate();

            this.setMonth(this.getMonth() + months);
            var currDt = this.getDate();

            if (dt !== currDt) {  
                this.addDays(-currDt);
            }

            return this;
        };

        Date.prototype.addYears = function(years) {
            var dt = this.getDate();

            this.setFullYear(this.getFullYear() + years);

            var currDt = this.getDate();

            if (dt !== currDt) {  
                this.addDays(-currDt);
            }

            return this;
        };