在Datepicker

时间:2015-10-15 18:47:24

标签: javascript jquery function datepicker

日期默认为明天的日期而不是今天的日期。

该网站是www.estesparkcabins.com/stiva/book.html

我认为我缩小了代码需要更改的位置。让我知道你的想法。非常感谢。

/* Get a setting value, defaulting if necessary. */
_get: function(inst, name) {
    return inst.settings[name] !== undefined ?
        inst.settings[name] : this._defaults[name];
},

/* Parse existing date and initialise date picker. */
_setDateFromField: function(inst, noDefault) {
    if (inst.input.val() === inst.lastVal) {
        return;
    }

    var dateFormat = this._get(inst, "dateFormat"),
        dates = inst.lastVal = inst.input ? inst.input.val() : null,
        defaultDate = this._getDefaultDate(inst),
        date = defaultDate,
        settings = this._getFormatConfig(inst);

    try {
        date = this.parseDate(dateFormat, dates, settings) || defaultDate;
    } catch (event) {
        dates = (noDefault ? "" : dates);
    }
    inst.selectedDay = date.getDate();
    inst.drawMonth = inst.selectedMonth = date.getMonth();
    inst.drawYear = inst.selectedYear = date.getFullYear();
    inst.currentDay = (dates ? date.getDate() : 0);
    inst.currentMonth = (dates ? date.getMonth() : 0);
    inst.currentYear = (dates ? date.getFullYear() : 0);
    this._adjustInstDate(inst);
},

/* Retrieve the default date shown on opening. */
_getDefaultDate: function(inst) {
    return this._restrictMinMax(inst,
        this._determineDate(inst, this._get(inst, "defaultDate"), new Date()));
},

/* A date may be specified as an exact value or a relative one. */
_determineDate: function(inst, date, defaultDate) {
    var offsetNumeric = function(offset) {
            var date = new Date();
            date.setDate(date.getDate() + offset);
            return date;
        },
        offsetString = function(offset) {
            try {
                return $.datepicker.parseDate($.datepicker._get(inst, "dateFormat"),
                    offset, $.datepicker._getFormatConfig(inst));
            }
            catch (e) {
                // Ignore
            }

            var date = (offset.toLowerCase().match(/^c/) ?
                $.datepicker._getDate(inst) : null) || new Date(),
                year = date.getFullYear(),
                month = date.getMonth(),
                day = date.getDate(),
                pattern = /([+\-]?[0-9]+)\s*(d|D|w|W|m|M|y|Y)?/g,
                matches = pattern.exec(offset);

            while (matches) {
                switch (matches[2] || "d") {
                    case "d" : case "D" :
                        day += parseInt(matches[1],10); break;
                    case "w" : case "W" :
                        day += parseInt(matches[1],10) * 7; break;
                    case "m" : case "M" :
                        month += parseInt(matches[1],10);
                        day = Math.min(day, $.datepicker._getDaysInMonth(year, month));
                        break;
                    case "y": case "Y" :
                        year += parseInt(matches[1],10);
                        day = Math.min(day, $.datepicker._getDaysInMonth(year, month));
                        break;
                }
                matches = pattern.exec(offset);
            }
            return new Date(year, month, day);
        },
        newDate = (date == null || date === "" ? defaultDate : (typeof date === "string" ? offsetString(date) :
            (typeof date === "number" ? (isNaN(date) ? defaultDate : offsetNumeric(date)) : new Date(date.getTime()))));

    newDate = (newDate && newDate.toString() === "Invalid Date" ? defaultDate : newDate);
    if (newDate) {
        newDate.setHours(0);
        newDate.setMinutes(0);
        newDate.setSeconds(0);
        newDate.setMilliseconds(0);
    }
    return this._daylightSavingAdjust(newDate);
},

它还有其他类似的js文件:

}).on("focusin.hb", ".hbSelectorDatepick", function (e) {
            if (datepicker) {
                var $this = pjQ.$(this),
                    dOpts = {
                    dateFormat: $this.data("dformat"),
                    firstDay: $this.data("fday"),
                    monthNamesShort: self.opts.month_names,
                    dayNamesMin: self.opts.day_names,
                    minDate: 1,
                    changeMonth: true
                };
                $this.datepicker(pjQ.$.extend(dOpts, {
                    beforeShow: function (input, ui) {
                        var dt_from, $chain,
                            name = ui.input.attr("name");

                        if 

                        (name == "date_from") {
                            ui.input.datepicker("option", "minDate", 0);
                        } else if (name == "date_to") {
                            $chain = ui.input.closest("form").find("input[name='date_from']");
                            dt_from = $chain.datepicker(dOpts).datepicker("getDate");
                            if (dt_from != null) {
                                ui.input.datepicker("option", "minDate", new Date(dt_from.getTime() + 86400*1000));
                            }
                        }

                        ui.dpDiv.addClass('stivaDatepicker');
                    },
                    onSelect: function (dateText, ui) {
                        var dt_from, dt_to, $dt_to;

                        if (ui.input.attr("name") == "date_from") {
                            $dt_to = ui.input.closest("form").find("input[name='date_to']");
                            dt_from = ui.input.datepicker(dOpts).datepicker("getDate");
                            dt_to = $dt_to.datepicker(dOpts).datepicker("getDate");

                            if (dt_from != null && dt_to != null && dt_from.getTime() > dt_to.getTime()) {
                                $dt_to.datepicker("option", "minDate", new Date(dt_from.getTime() + 86400*1000));
                            }
                        }
                    }
                }));
            }

1 个答案:

答案 0 :(得分:0)

这很简单,你不需要改变任何东西。只需更改日期选择器的初始化代码即可。

// The value depends of some factors, you need to play around it self.tableView.contentInset = UIEdgeInsetsMake(-65, 0, 0, 0)