输入日历跳转到下一个输入

时间:2014-02-25 16:16:51

标签: javascript calendar

我正在使用这个日历,并且“我被迫使用它”,我想知道你是否可以帮我解决一个小问题。

日历:http://www.bulgaria-web-developers.com/projects/javascript/calendar/

我有2个此日历所在的输入字段,

<input type="text" id="cr_date_from" />
<input type="text" id="cr_date_to" />

在“date_from”中选择日期之后,我需要它跳转到“date_to”并且具有与date_from字段中选择的日期相同的日期。因为当人们提前几个月选择一个日期时,这不会引起混淆,也不会在date_to中一直滚动到那个日期......

我已经尝试了一段时间没有运气,所以我希望你们能够帮助我......

感谢所有帮助!

这里也是那些感兴趣的人的javascript ...

bindSearch: function () {
        var self = this,
            dateFrom = new Calendar({
                element: "cr_date_from",
                //dateFormat: "Y-m-d",
                dateFormat: self.opts.dateFormat,
                monthNamesFull: self.opts.monthNamesFull,
                dayNames: self.opts.dayNames,
                disablePast: true,
                months: 3,
                onSelect: function () {
                    reCalc.call(self);
                }
            }),
            dateTo = new Calendar({
                element: "cr_date_to",
                //dateFormat: "Y-m-d",
                dateFormat: self.opts.dateFormat,
                monthNamesFull: self.opts.monthNamesFull,
                dayNames: self.opts.dayNames,
                disablePast: true,
                months: 3,
                onSelect: function () {
                    reCalc.call(self);
                }
            }),
            lnkFrom = document.getElementById("crDateFrom"),
            lnkTo = document.getElementById("crDateTo"),
            btnQuote = document.getElementById("crBtnQuote"),
            btnMap = document.getElementById("crBtnMap"),
            sameLoc = document.getElementById("cr_same_location"),
            returnLoc = document.getElementById("crReturnBox");

        self.elFrom = document.getElementById("cr_date_from");
        self.elTo = document.getElementById("cr_date_to");
        self.elHFrom = document.getElementById("cr_hour_from");
        self.elMFrom = document.getElementById("cr_minutes_from");
        self.elHTo = document.getElementById("cr_hour_to");
        self.elMTo = document.getElementById("cr_minutes_to");

        function reCalc() {
            var from = Date.parseExact(this.elFrom.value, dateFormat(self.opts.dateFormat, 'datejs')).getTime() + (parseInt(this.elHFrom.value, 10) * 3600000) + (parseInt(this.elMFrom.value, 10) * 60000),
                to = Date.parseExact(this.elTo.value, dateFormat(self.opts.dateFormat, 'datejs')).getTime() + (parseInt(this.elHTo.value, 10) * 3600000) + (parseInt(this.elMTo.value, 10) * 60000),
                nd = document.getElementById("crNumDays"),
                days;
            if (from !== null && to !== null) {
                days = Math.ceil((to - from) / 86400000);
                if (days > 0) {
                    nd.lastChild.innerHTML = days;
                    nd.style.display = "";
                } else {
                    nd.style.display = "none";
                }
            } else {
                nd.style.display = "none";
            }
        }   

        if (lnkFrom) {
            lnkFrom.onclick = function (e) {
                if (e && e.preventDefault) {
                    e.preventDefault();
                }
                dateFrom.isOpen ? dateFrom.close() : dateFrom.open();
                return false;
            };
        }
        if (lnkTo) {
            lnkTo.onclick = function (e) {
                if (e && e.preventDefault) {
                    e.preventDefault();
                }
                dateTo.isOpen ? dateTo.close() : dateTo.open();
                return false;
            };
        }
        if (btnMap) {
            btnMap.onclick = function (e) {
                self.overlayMap.open();
                if (e && e.preventDefault) {
                    e.preventDefault();
                }
                return false;
            }
        }
        if (sameLoc && returnLoc) {
            function bindLoc(el) {
                if (this.checked) {
                    el.style.display = "none";
                } else {
                    el.style.display = "";
                }
            }
            sameLoc.onchange = function () {
                bindLoc.call(this, returnLoc);
            };
            sameLoc.onclick = function () {
                bindLoc.call(this, returnLoc);
            };
        }
        if (btnQuote) {
            btnQuote.onclick = function () {
                this.disabled = true;
                if (!self.validateSearch(this)) {
                    this.disabled = false;
                    return;
                }
                self.passed.first = true;
                self.loadCars.apply(self, [JABB.Utils.serialize(document.getElementById("crFormSearch"))]);
            };
        }
    },

0 个答案:

没有答案