glDatePicker可选日期范围的反转顺序

时间:2013-03-13 14:55:46

标签: jquery math

规格明显改变,我无法理解为什么这不起作用。我有一个带#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”不起作用,任何想法?

1 个答案:

答案 0 :(得分: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();
});
});