0

我正在使用此代码在我的页面上创建一个 jquery 日历

$(function(){
    //set the datepicker
    var dateToday = new Date();
    $('#pikdate').datetimepicker({       
        minDate: dateToday,
        dateFormat: 'dd/mm/yy',
        defaultDate: '+1w'
    });   
}); 

如何在此日历中添加一天,该日历应从 24 小时后开始。

4

2 回答 2

0

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

$(function(){
   //set the datepicker
   var dateToday = new Date();

   dateToday.addDays(1); // it will add one day to the current date (ps: add the following functions)

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

但是要使“addDays”函数起作用,您必须创建该函数,如下所示。

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

你可以在这里看到一个例子:http: //jsfiddle.net/tiagoajacobi/YHA8x/

这是功能:

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

它们是原型函数,这意味着“日期”类型的每个变量都将具有此函数。

于 2014-05-09T18:29:11.097 回答
0

你可以这样做。

$('#pikdate').datepicker({       
      minDate: dateToday,
      dateFormat: 'dd/mm/yy',
      defaultDate: '+1w'
});   
于 2013-07-17T07:34:31.887 回答