0

规格显然发生了变化,我无法理解为什么这不起作用。我有一个带有 #StartDate 和 #EndDate 字段的表单

<ul>
    <li>
        <label for="StartDate">Start Date</label>
        <input type="text" id="StartDate" name="StartDate">
    </li>
    <li>    
        <label for="EndDate">End Date</label>
        <input type="text" id="EndDate" name="EndDate">
        <input type="submit" id="Button6" value="foo" />
    </li>
    <li>
        <label for="AllDates"><input type="checkbox" name="AllDates" id="AllDates" value="YES">All Dates</label>
    </li>
</ul>

以前当日期范围从今天开始时 - 向前这有效:

$("#bottomContent").on('focus', "#StartDate", function(){
    var today = new Date();
    var datelimit = new Date(today);
    datelimit.setDate(today.getDate() + 31);

    $(this).glDatePicker({
        showAlways: false,
        allowMonthSelect: true,
        allowYearSelect: true,
        prevArrow:'<',
        nextArrow:'>',
        selectedDate:today,
        selectableDateRange: [{
            from: today,
            to: datelimit
        }, ],
        onClick: function (target, cell, date, data) {
            target.val((date.getMonth() +1) + '/' + date.getDate() + '/' + date.getFullYear());
            $('#AllDates').prop('checked', false);
            if (data != null) {
                alert(data.message + '\n' + date);
            }
        }
}).glDatePicker(true);

var to = $('#EndDate').glDatePicker({
    showAlways: false,
    onClick: function (target, cell, date, data) {
        target.val((date.getMonth() +1) + '/' + date.getDate() + '/' + date.getFullYear());
        $('#AllDates').prop('checked', false);
        if (data != null) {
            alert(data.message + '\n' + date);
        }
    }
}).glDatePicker(true);
$("#bottomContent").on('focus', "#EndDate", function(){
    var dateFrom = new Date($("#StartDate").val());
    var toLimit = new Date();
    toLimit.setDate(dateFrom.getDate() + 31);
    to.options.selectableDateRange = [{
    from: dateFrom,
    to: toLimit
}, ],
    to.options.showAlways = false;
    to.render();
});});

我需要让它从今天开始 = newDate() 并让它向后退(-365 天),但只需将所有“+ 31”切换为“- 365”,这将使其前进一个月是行不通的,任何想法?

4

1 回答 1

0

如果有人遇到同样的问题,就这样做了。

$("#bottomContent").on('focus', "#StartDate", function(){
var today = new Date("January 1, 2013");
var datelimit = new Date();
datelimit.setDate(today.getDate() +14);

$(this).glDatePicker({
    showAlways: false,
    allowMonthSelect: true,
    allowYearSelect: true,
    prevArrow:'<',
    nextArrow:'>',
    selectedDate:today,
    selectableDateRange: [{
        from: today,
        to: datelimit
    }, ],
    onClick: function (target, cell, date, data) {
    target.val((date.getMonth() +1) + '/' + date.getDate() + '/' + date.getFullYear());
        $('#AllDates').prop('checked', false);
    if (data != null) {
        alert(data.message + '\n' + date);
    }
}
}).glDatePicker(true);

var to = $('#EndDate').glDatePicker({
    showAlways: false,
    prevArrow:'<',
    nextArrow:'>',
    selectedDate:today,
    onClick: function (target, cell, date, data) {
        target.val((date.getMonth() +1) + '/' + date.getDate() + '/' + date.getFullYear());
        $('#AllDates').prop('checked', false);
        if (data != null) {
            alert(data.message + '\n' + date);
        }
    }
    }).glDatePicker(true);
$("#bottomContent").on('focus', "#EndDate", function(){

var dateFrom = new Date($("#StartDate").val());
var toLimit = new Date();
//toLimit.setDate(dateFrom.getDate());
to.options.selectableDateRange = [{
    from: dateFrom,
    to: toLimit
}, ],
to.options.showAlways = false;
to.render();
});
});
于 2013-03-13T16:18:45.113 回答