datetimepicker update mindate maxdate

时间:2014-06-18 17:52:50

标签: javascript jquery datetimepicker

我在两个文本框中使用jquery datetimepicker从日期到日期。我想从其他文本框更新值mindate和maxdate。它第一次正常工作,但如果我更改调试的值是正确的,但datetimepicker没有更新。我的问题是我将如何使datetimepicker更新。阅读代码我认为更清楚。谢谢

    $(".DatePickerFieldOnHire").live('click', function () {

        var defaultDateTime = "";
        var dateFrom = "";
        var dateTo = "";
        dateFrom = document.getElementById('WebReportForm1_Value_DeliveryDate').value;
        dateTo = document.getElementById('WebReportForm1_Value_ExpectedRedeliveryDate').value;
        var now = new Date();
        var dateNow=now.format("dd-mm-yy HH:mm z");

dateFrom = document.getElementById('WebReportForm1_Value_DeliveryDate').value;
            dateTo = document.getElementById('WebReportForm1_Value_ExpectedRedeliveryDate').value;
            var now = new Date();
            var dateNow=now.format("dd-mm-yy HH:mm z");

            if (dateFrom == null) {
                dateFrom = new Date(1999, 10 - 1, 25);
            }
            if (dateTo == null) {
                dateTo = new Date(2055, 10 - 1, 25);
                defaultDateTime = dateNow;
            } else {
                if (dateTo > dateNow) {
                    defaultDateTime = dateNow;
                }
                else {
                    defaultDateTime = dateTo;
                }
            }          
            var inputOff = "";
            inputOff = $('[id*="OffHireDateField"]').val();
            if (inputOff != "") {
               dateFrom = inputOff;
            }

            $(this).datetimepicker({
             showOn: 'focus', showTimezone: false, ampm: true, dateFormat: "dd-mm-yy",
                timeFormat: "HH:mm z",
                minDate: dateFrom,
                maxDate: dateTo,
                showTimezone: true,
                defaultDate: defaultDateTime,
                onSelect: function () { }
            }).focus();

        });

和From文本框

 $(".DatePickerFieldOffHire").live('click', function () {

        var dateFrom = "";
        var dateTo = "";
        dateFrom = document.getElementById('WebReportForm1_Value_DeliveryDate').value;
        dateTo = document.getElementById('WebReportForm1_Value_ExpectedRedeliveryDate').value;


        if (dateFrom == null) {
            dateFrom = new Date(1999, 10 - 1, 25);
        }

        if (dateTo == null) {
            dateTo = new Date(2055, 10 - 1, 25);
            defaultDateTime = dateNow;
        } else {
            if (dateTo > dateNow) {
                defaultDateTime = dateNow;
            }
            else {
                defaultDateTime = dateTo;
            }
        }

        var inputOn = "";
        inputOn = $('[id*="OnHireDateField"]').val();
        if (inputOn != "") {
            dateTo = inputOn;
        }

        $(this).datetimepicker({
            showOn: 'focus', showTimezone: false, ampm: true, dateFormat: "dd-mm-yy",
            timeFormat: "HH:mm z",
            minDate: dateFrom,
            maxDate: dateTo,
            showTimezone: true,
            defaultDate: defaultDateTime,
            onSelect: function () { }
        }).focus();

    });

1 个答案:

答案 0 :(得分:0)

我必须承认,我没有彻底检查代码,因为你没有包含JSFiddle,但从我所看到的情况来看,它看起来像第一次,dateFromdateTo { {1}}对象,但从第二次起,它们是Date

这可能是一个问题。

您的日期格式Strings不符合default format dd-mm-yy